[Q] [Solved]Calling a method of parent fragment from child fragment - Java for Android App Development

TabFragment
Code:
public class TabFragment extends android.support.v4.app.Fragment
{List fragments = new Vector();
PagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
public View onCreateView (LayoutInflater inflater , ViewGroup container ,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup ) inflater .inflate(
R . layout.tabfragment , container , false );
mSectionsPagerAdapter = new ScreenSlidePagerAdapter (getActivity().getSupportFragmentManager ());
mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
//for each fragment
add();
//(android.support.v4.app.Fragment.instantiate(this,Main.class.getName(),page));
mViewPager.setAdapter(mSectionsPagerAdapter);
return rootView ;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter
{
@Override
public CharSequence getPageTitle(int position)
{return fragments.get(position).getArguments().getString("name");
}
public int getCount()
{
// TODO: Implement this method
return fragments.size();
}
public ScreenSlidePagerAdapter ( android.support.v4.app.FragmentManager fm ) {
super ( fm);
}
@Override
public android.support.v4.app.Fragment getItem ( int position ) {
android.support.v4.app.Fragment f;
f= fragments.get(position);
return f;
}
}
public void add(){
android.support.v4.app.Fragment main=new Main();
Bundle b=new Bundle();
int p=fragments.size();
b.putString("name","Sdcard");
b.putInt("pos",p);
main.setArguments(b);
fragments.add(main);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setCurrentItem(p);
}
}
//Here "new Main()" refers to a child fragment
Now I want to execute the method "add" of above posted "TabFragment" in the child fragment "Main"
Please help for the same
Sent from my GT-S5570 using XDA Premium 4 mobile app

arpitkh96 said:
TabFragment
Code:
public class TabFragment extends android.support.v4.app.Fragment
{List<android.support.v4.app.Fragment> fragments = new Vector<android.support.v4.app.Fragment>();
PagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
public View onCreateView (LayoutInflater inflater , ViewGroup container ,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup ) inflater .inflate(
R . layout.tabfragment , container , false );
mSectionsPagerAdapter = new ScreenSlidePagerAdapter (getActivity().getSupportFragmentManager ());
mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
//for each fragment
add();
//(android.support.v4.app.Fragment.instantiate(this,Main.class.getName(),page));
mViewPager.setAdapter(mSectionsPagerAdapter);
return rootView ;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter
{
@Override
public CharSequence getPageTitle(int position)
{return fragments.get(position).getArguments().getString("name");
}
public int getCount()
{
// TODO: Implement this method
return fragments.size();
}
public ScreenSlidePagerAdapter ( android.support.v4.app.FragmentManager fm ) {
super ( fm);
}
@Override
public android.support.v4.app.Fragment getItem ( int position ) {
android.support.v4.app.Fragment f;
f= fragments.get(position);
return f;
}
}
public void add(){
android.support.v4.app.Fragment main=new Main();
Bundle b=new Bundle();
int p=fragments.size();
b.putString("name","Sdcard");
b.putInt("pos",p);
main.setArguments(b);
fragments.add(main);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setCurrentItem(p);
}
}
//Here "new Main()" refers to a child fragment
Now I want to execute the method "add" of above posted "TabFragment" in the child fragment "Main"
Please help for the same
Sent from my GT-S5570 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
You should use an EventBus for similar cases. Try Square's Otto, available on GitHub.

Related

Problem of flashlight app code (Eclipse)

Hello everyone ..
I have problem on developing a flashlight app
I tried the solutions that provided by Eclipse but none solved the problem
or even make any sense to me :angel:
every "Void" statement on the code appeared as an error
and i don't know why .. also i'm sure that everything on the code is correct
Examples of the errors:
private void playSound() {
private void toggleButtonImage() {
private void turnOffFlash() {
and .. etc , i got an error on every "Void" !
so.. i'm waiting for your opinions
Thanks in advance )​
Hi,
It is impossible for us to tell you what you have done wrong if you do not post your source code.
It could be just one character missing somewhere or one to much.
We need your code to help you.
(If you do not want to release it completely, copy your project and remove those parts you do not want us to see. This could also help you with finding the error yourself. )
nikwen said:
Hi,
It is impossible for us to tell you what you have done wrong if you do not post your source code.
It could be just one character missing somewhere or one to much.
We need your code to help you.
(If you do not want to release it completely, copy your project and remove those parts you do not want us to see. This could also help you with finding the error yourself. )
Click to expand...
Click to collapse
Thanks 4 answering me nikwen
i tried to post a screenshot of the problem but i'm a new member in the forum so i couldn't post an external link
anyway .. here's the Code
package com.mohamedsherif.flashlighttorch;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
ImageButton switchButton;
private Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.switchButton);
//Check if the Device has Flash
hasFlash = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!hasFlash) {
AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
alert.setTitle("Error! ");
alert.setMessage("Sorry! .. Your device doesn't have a flash!");
alert.setButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
finish();
}
});
alert.show();
return;
}
//Getting camera parameters
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to open. Error", e.getMessage());
}
}
}
private void turnOnFlash() {
if (!hasFlash) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
toggleButtonImage();
}
}
//Turning off flash
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
toggleButtonImage();
}
};
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
});
// Toggle buttons images
private void toggleButtonImage() {
if (isFlashOn) {
switchButton.setImageResource(R.drawable.switch_on);
} else {
switchButton.setImageResource(R.drawable.switch_off);
}
}
// Playing Sound
private void playSound() {
if (isFlashOn) {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_off);
} else {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_on);
}
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Click to expand...
Click to collapse
the errors are in RED ​
little changes
private static Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
ToggleButton switchButton;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flashlight);
getCamera();
switchButton = (ToggleButton) findViewById(R.id.tglOnOffFlashlight);
switchButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
});
//Check if the Device has Flash
hasFlash = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!hasFlash) {
AlertDialog alert = new AlertDialog.Builder(FlashlightActivity.this).create();
alert.setTitle("Error! ");
alert.setMessage("Sorry! .. Your device doesn't have a flash!");
alert.setButton("ok", new DialogInterface.OnClickListener() {
@override
public void onClick(final DialogInterface dialog, final int which) {
finish();
}
});
alert.show();
return;
}
}
//Getting camera parameters
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to open. Error", e.getMessage());
}
}
}
private void turnOnFlash() {
if (hasFlash) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
toggleButtonImage();
}
}
//Turning off flash
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
toggleButtonImage();
}
}
// Toggle buttons images
private void toggleButtonImage() {
if (isFlashOn) {
switchButton.setBackgroundResource(R.drawable.on_yellow );
} else {
switchButton.setBackgroundResource(R.drawable.off_white);
}
}
// Playing Sound
private void playSound() {
if (isFlashOn) {
mp = MediaPlayer.create(FlashlightActivity.this, R.raw.light_switch_off);
} else {
mp = MediaPlayer.create(FlashlightActivity.this, R.raw.light_switch_on);
}
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}
these work
Does it work on other projects?
It is working for him, so I guess that the errors are not in the code but maybe your project setup or your installation of Eclipse and the Android SDK is the reason for that.
So to quote myself " Does it work on other projects?".
---------- Post added at 09:59 PM ---------- Previous post was at 09:55 PM ----------
Oh no, there are mistakes with the brackets.
For example you set a listener somewhere inside a methods. However, you forgot to close the bracket (I mean these ones {}). So it ends with a semicolon. It wants more lines of code.
So check your brackets.
Void methods should not return anything. So you can remove all 'return' words in the void methods.
Sent from my NexusHD2 using xda app-developers app
Eztys said:
Void methods should not return anything. So you can remove all 'return' words in the void methods.
Sent from my NexusHD2 using xda app-developers app
Click to expand...
Click to collapse
These returns ARE allowed. They are not necessary but allowed. You can stop the method by this.
It is really a problem with these brackets {}.
krsln said:
private static Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
ToggleButton switchButton;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flashlight);
getCamera();
switchButton = (ToggleButton) findViewById(R.id.tglOnOffFlashlight);
switchButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
these work
Click to expand...
Click to collapse
the same problem with the Void errors !! -.-
nikwen said:
Does it work on other projects?
It is working for him, so I guess that the errors are not in the code but maybe your project setup or your installation of Eclipse and the Android SDK is the reason for that.
So to quote myself " Does it work on other projects?".
---------- Post added at 09:59 PM ---------- Previous post was at 09:55 PM ----------
Oh no, there are mistakes with the brackets.
For example you set a listener somewhere inside a methods. However, you forgot to close the bracket (I mean these ones {}). So it ends with a semicolon. It wants more lines of code.
So check your brackets.
Click to expand...
Click to collapse
i tried the code on a new project but i got the same errors
also i don't think there's any problem with the brackets ?
Eztys said:
Void methods should not return anything. So you can remove all 'return' words in the void methods.
Sent from my NexusHD2 using xda app-developers app
Click to expand...
Click to collapse
the return is not the problem ​
i just solved the void errors but the app is not running on the virtual device !
"the app has stopped unexpectedly"
can anyone try the code ? or even tell me what's wrong ?
BTW the code doesn't contain any errors now .. not even the void errors
package com.mohamedsherif.flashlighttorch;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton switchButton;
private Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.switchButton);
//Check if the Device has Flash
hasFlash = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!hasFlash) {
AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
alert.setTitle("Error! ");
alert.setMessage("Sorry! .. Your device doesn't have a flash!");
alert.setButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
finish();
}
});
alert.show();
return;
}
getCamera();
toggleButtonImage();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
});
}
//Getting camera parameters
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to open. Error: ", e.getMessage());
}
}
}
private void turnOnFlash() {
if (!hasFlash) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
toggleButtonImage();
}
}
//Turning off flash
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
toggleButtonImage();
}
};
// Toggle buttons images
private void toggleButtonImage() {
if (isFlashOn) {
switchButton.setImageResource(R.drawable.switch_on);
} else {
switchButton.setImageResource(R.drawable.switch_off);
}
}
// Playing Sound
private void playSound() {
if (isFlashOn) {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_off);
} else {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_on);
}
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
turnOffFlash();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (hasFlash)
turnOnFlash();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
getCamera();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
if (camera != null) {
camera.release();
camera = null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Click to expand...
Click to collapse
M. Sherif said:
i just solved the void errors but the app is not running on the virtual device !
"the app has stopped unexpectedly"
can anyone try the code ? or even tell me what's wrong ?
BTW the code doesn't contain any errors now .. not even the void errors
​
Click to expand...
Click to collapse
There will be a logcat. Post it here.

database connect doesn't work properly

i've need to connect my app to an external database so i put my sqlite database on assets folder and i've follow this tutorial to make DBHelper.
now i want to show some record of database in my app but when i launch it, it give me an error like a table "linee" doesn't exists on my database but it exists!!!! this link cans proof it http://img689.imageshack.us/img689/926/ytvo.png
why???? it's a week that i can to fix this problem but i can't solve it
this is MyOpenHelper
Code:
public class MyOpenHelper extends SQLiteOpenHelper{
//The Android's default system path of your application database.
private static String DB_PATH ;
private SQLiteDatabase db;
private static String DB_NAME = "orari";
private final Context myContext;
public MyOpenHelper(Context context) {
super(context, DB_NAME, null, 1);// 1? its Database Version
if(android.os.Build.VERSION.SDK_INT >= 4.2){
DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
} else {
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
}
this.myContext = context;
}
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
}else{
this.getReadableDatabase();
try{
copyDataBase();
}catch (IOException e){
throw new Error("Errore nel copiare il database");
}
}
}
private boolean checkDataBase(){
File dbFile=new File(DB_PATH+DB_NAME);
return dbFile.exists();
}
private void copyDataBase() throws IOException{
InputStream myInput=myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH+DB_NAME;
OutputStream myOutput=new FileOutputStream(outFileName);
byte[] buffer = new byte [1024];
int length;
while ((length=myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
public void openDataBase() throws SQLException{
String myPath=DB_PATH+DB_NAME;
db=SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
[user=439709]@override[/user]
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
[user=439709]@override[/user]
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}

Retrieving cpu frequency

Hi everyone.
I want to retrieve the current cpu frequency in my app but I don't seem to be right.
In my code I want to read the "scaling_cpu_freq" file from internal storage.
This is the code:
Code:
private String ReadCPUMhz() {
String cpuMaxFreq = "";
int cur = 0;
try {
[user=1299008]@supp[/user]ressWarnings("resource")
BufferedReader maxi = new BufferedReader(new FileReader(new File("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq")));
try{
cpuMaxFreq = maxi.readLine();
cur = Integer.parseInt(cpuMaxFreq);
cur = cur/1000;
} catch (Exception ex){
ex.printStackTrace();
}
} catch (FileNotFoundException f) {
f.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return String.valueOf(cur);
}
The problem is that the method only returns 0, which is the initial value of the int "cur".
Can anybody help me?
Thanks in advance.
Here's the code I use:
Declare this class in your Activity
Code:
// Read current frequency from /sys in a separate thread
// This class assumes your TextView is declared and referenced in the OnCreate of the class this one is declared in
// And its variable name is mCurCpuFreq
protected class CurCPUThread extends Thread {
private static final String CURRENT_CPU = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq";
private boolean mInterrupt = false;
public void interrupt() {
mInterrupt = true;
}
[user=439709]@override[/user]
public void run() {
try {
while (!mInterrupt) {
sleep(400);
final String curFreq = readOneLine(CURRENT_CPU);
mCurCPUHandler.sendMessage(mCurCPUHandler.obtainMessage(0,
curFreq));
}
} catch (InterruptedException e) {
return;
}
}
}
// Update real-time current frequency & stats in a separate thread
protected static Handler mCurCPUHandler = new Handler() {
public void handleMessage(Message msg) {
mCurFreq.setText(toMHz((String) msg.obj));
final int p = Integer.parseInt((String) msg.obj);
new Thread(new Runnable() {
public void run() {
// Here I update a real-time graph of the current freq
}
}
}).start();
}
};
Helper methods used :
Code:
// Convert raw collected values to formatted MhZ
private static String toMHz(String mhzString) {
if (Integer.valueOf(mhzString) != null)
return String.valueOf(Integer.valueOf(mhzString) / 1000) + " MHz";
else
return "NaN";
}
// Iterate through the /sys file
public static String readOneLine(String fname) {
BufferedReader br;
String line = null;
try {
br = new BufferedReader(new FileReader(fname), 512);
try {
line = br.readLine();
} finally {
br.close();
}
} catch (Exception e) {
Log.e(TAG, "IO Exception when reading sys file", e);
// attempt to do magic!
return readFileViaShell(fname, true);
}
return line;
}
// Backup method if the above one fails
public static String readFileViaShell(String filePath, boolean useSu) {
CommandResult cr = null;
if (useSu) {
cr = new CMDProcessor().runSuCommand("cat " + filePath);
} else {
cr = new CMDProcessor().runShellCommand("cat " + filePath);
}
if (cr.success())
return cr.getStdout();
return null;
}
CMDProcessor.java and its dependencies attached to this post

[Q] How do I add an image picker to my app, show it in image view, then save it to pa

This is what I have:
Code:
package JEB.ssf;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.*;
import android.view.View.*;
import com.parse.*;
import android.content.*;
import android.support.v4.app.*;
import java.util.*;
import android.widget.AdapterView.*;
import android.util.*;
import com.google.android.gms.ads.*;
import com.google.ads.mediation.*;
import com.google.ads.*;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdListener;
import android.provider.*;
import android.database.*;
import android.graphics.*;
public class ProfilePage extends Activity
{
private static int LOAD_IMAGE_RESULTS = 1;
// GUI components
private Button button; // The button
private ImageView image;// ImageView
Spinner sp1,sp2;
ArrayAdapter<String> adp1,adp2, adp3;
List<String> l1,l2, l3;
int pos;
EditText fname, lname, hf, hi, weight,
waist, wrist, hip, forearm, age, goal;
TextView userName, gender, category, unit;
String hftxt, hitxt, id, firstNameTxt, userNameTxt, posttxt, postnum;
Button share;
float obid;
int in;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile_page);
getActionBar().setDisplayHomeAsUpEnabled(true);
Parse.initialize(this, "abmPl8JnnhyaqjA0Pp8ZWmptKTCeV0p8eoMEHPaL", "icKQxW5AdPXHJtsGEqSX5LwJ2Dd8zt0USKd1PNeP");
fname = (EditText) findViewById(R.id.first_name);
lname = (EditText) findViewById(R.id.last_name);
hf = (EditText) findViewById(R.id.height_feet);
hi = (EditText) findViewById(R.id.height_inch);
weight = (EditText) findViewById(R.id.weight_lbs);
waist = (EditText) findViewById(R.id.waist);
wrist = (EditText) findViewById(R.id.wrist);
hip = (EditText) findViewById(R.id.hip);
forearm = (EditText) findViewById(R.id.forearm);
age = (EditText) findViewById(R.id.age);
userName = (TextView) findViewById(R.id.user_name);
gender = (TextView) findViewById(R.id.gender);
category = (TextView) findViewById(R.id.category);
unit =(TextView) findViewById(R.id.unit);
goal =(EditText) findViewById(R.id.goal);
share = (Button) findViewById(R.id.share);
Intent i = getIntent();
userNameTxt = i.getStringExtra("user_name");
userName.setText(userNameTxt);
button = (Button)findViewById(R.id.image_pick);
image = (ImageView)findViewById(R.id.image);
gender_button();
category_button();
unit_button();
image_button();
share_button();
small_banner_ad();
final ParseQuery<ParseObject> query = ParseQuery.getQuery("profile_info");
// Restrict to cases where the author is the current user.
// Note that you should pass in a ParseUser and not the
// String reperesentation of that user
query.whereEqualTo("user_data", ParseUser.getCurrentUser());
// Run the query
query.findInBackground(new FindCallback<ParseObject>() {
public String TAG;
[user=439709]@override[/user]
public void done(List<ParseObject> postList, ParseException e) {
if (e == null) {
// If there are results, update the list of posts
// and notify the adapter
for (ParseObject profile_info : postList) {
userName.setText(profile_info.getString("user_name"));
fname.setText(profile_info.getString("first_name"));
lname.setText(profile_info.getString("last_name"));
hf.setText(profile_info.getString("height_in_feet"));
hi.setText(profile_info.getString("height_in_inches"));
weight.setText(profile_info.getString("weight"));
waist.setText(profile_info.getString("waist"));
wrist.setText(profile_info.getString("wrist"));
hip.setText(profile_info.getString("hip"));
forearm.setText(profile_info.getString("forearm"));
age.setText(profile_info.getString("age"));
gender.setText(profile_info.getString("gender"));
category.setText(profile_info.getString("category"));
unit.setText(profile_info.getString("unit"));
goal.setText(profile_info.getString("goal"));
}
} else {
Log.d("Post retrieval", "Error: " + e.getMessage());
}
}});
}
private void share_button()
{
share.setOnClickListener(new OnClickListener() {
public void onClick(View arg1) {
final ParseObject posts = new ParseObject("posts");
posts.put("user_name", userName.getText().toString());
posts.put("category", "My goal is to" + " "+category.getText()+" "+goal.getText()+" "+unit.getText().toString());
// Create an user data relationship with the current user
posts.put("user_posts", ParseUser.getCurrentUser());
// Save the post and return
posts.saveInBackground(new SaveCallback () {
[user=439709]@override[/user]
public void done(ParseException e) {
if (e == null) {
setResult(RESULT_OK);
Toast.makeText(getApplicationContext(),"post successfull",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error sharing: " + e.getMessage(),
Toast.LENGTH_SHORT)
.show();
}
}});
}
});
}
private void unit_button()
{
unit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(ProfilePage.this, unit);
//Inflating the Popup using xml file
if (category.getText().toString().equals("Loose Weight")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Target Weight")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Gain Weight")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Build Muscle")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Run")){
popup.getMenuInflater()
.inflate(R.menu.distance_menu, popup.getMenu());
}if(category.getText().toString().equals("Walk")){
popup.getMenuInflater()
.inflate(R.menu.distance_menu, popup.getMenu());
}
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.lbs:
//act for menu_item1
unit.setText("lbs");
return true;
case R.id.mile:
//act for sub_menu_item1
unit.setText("Mile");
return true;
case R.id.k:
//act for sub_menu_item1
unit.setText("K");
return true;
default:
//pass the event to parent, for options menu, use below
}
return false;
}
});
popup.show(); //showing popup menu
}
}); //closing the setOnClickListener method
}
private void category_button()
{
category.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(ProfilePage.this, category);
//Inflating the Popup using xml file
popup.getMenuInflater()
.inflate(R.menu.category_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.target_weight:
category.setText("Target Weight");
return true;
case R.id.loose_weight:
//act for menu_item1
category.setText("Loose Weight");
return true;
case R.id. gain_weight:
//act for sub_menu_item1
category.setText("Gain Weight");
return true;
case R.id. build_muscle:
//act for sub_menu_item1
category.setText("Build Muscle");
return true;
case R.id. run:
//act for sub_menu_item1
category.setText("Run");
return true;
case R.id. walk:
//act for sub_menu_item1
category.setText("Walk");
return true;
default:
//pass the event to parent, for options menu, use below
}
return false;
}
});
popup.show(); //showing popup menu
}
}); //closing the setOnClickListener method
}
private void gender_button()
{
gender.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(ProfilePage.this, gender);
//Inflating the Popup using xml file
popup.getMenuInflater()
.inflate(R.menu.gender_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id. male:
//act for menu_item1
gender.setText("Male");
return true;
case R.id. female:
//act for sub_menu_item1
gender.setText("Female");
return true;
default:
//pass the event to parent, for options menu, use below
}
return false;
}
});
popup.show(); //showing popup menu
}
}); //closing the setOnClickListener method
}
private void small_banner_ad()
{
AdView adView = (AdView) this.findViewById(R.id.adView);
//request TEST ads to avoid being disabled for clicking your own ads
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)// This is for emulators
//test mode on DEVICE (this example code must be replaced with your device uniquq ID)
.addTestDevice("15174709D5FCBF710958952E2589F20D") // Nexus 6
.build();
adView.loadAd(adRequest);
}
private void save_update_button()
{
ParseUser.getCurrentUser();
ParseQuery<ParseObject> pQuery = new ParseQuery<ParseObject>("profile_info");
pQuery.whereEqualTo("user_name", userName.getText().toString());
pQuery.getFirstInBackground(new GetCallback<ParseObject>()
{ [user=439709]@override[/user]
public void done(ParseObject update, ParseException e) {
if (e == null){
update.put("user_name", userName.getText().toString());
update.put("first_name", fname.getText().toString());
update.put("last_name", lname.getText().toString());
update.put("height_in_feet", hf.getText().toString());
update.put("height_in_inches", hi.getText().toString());
update.put("weight", weight.getText().toString());
update.put("waist", waist.getText().toString());
update.put("wrist", wrist.getText().toString());
update.put("hip", hip.getText().toString());
update.put("forearm", forearm.getText().toString());
update.put("age", age.getText().toString());
update.put("gender", gender.getText().toString());
update.put("category", category.getText().toString());
update.put("unit", unit.getText().toString());
update.put("goal", goal.getText().toString());
update.saveInBackground();
Toast.makeText(getApplicationContext(),
"Your profile has been updated",
Toast.LENGTH_SHORT)
.show();
} else {
final ParseObject profile_info = new ParseObject("profile_info");
profile_info.put("user_name", userNameTxt);
profile_info.put("first_name", fname.getText().toString());
profile_info.put("last_name", lname.getText().toString());
profile_info.put("height_in_feet", hf.getText().toString());
profile_info.put("height_in_inches", hi.getText().toString());
profile_info.put("weight", weight.getText().toString());
profile_info.put("waist", waist.getText().toString());
profile_info.put("wrist", wrist.getText().toString());
profile_info.put("hip", hip.getText().toString());
profile_info.put("forearm", forearm.getText().toString());
profile_info.put("age", age.getText().toString());
profile_info.put("gender", gender.getText().toString());
profile_info.put("category", category.getText().toString());
profile_info.put("unit", unit.getText().toString());
profile_info.put("goal", goal.getText().toString());
// Create an user data relationship with the current user
profile_info.put("user_data", ParseUser.getCurrentUser());
// Save the post and return
profile_info.saveInBackground(new SaveCallback () {
[user=439709]@override[/user]
public void done(ParseException e) {
if (e == null) {
setResult(RESULT_OK);
Toast.makeText(getApplicationContext(),"Profile saved",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error saving: " + e.getMessage(),
Toast.LENGTH_SHORT)
.show();
}
}});
}
}
});
}
//image button
public void image_button(){
image.setOnClickListener(new OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
// Create the Intent for Image Gallery.
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start new activity with the LOAD_IMAGE_RESULTS to handle back the results when image is picked from the Image Gallery.
startActivityForResult(i, LOAD_IMAGE_RESULTS);
}});
}
//menu [user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.profile_menu, menu);
return super.onCreateOptionsMenu(menu);
}
[user=439709]@override[/user]
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
// Handle action buttons
switch(item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.logout:
ParseUser.logOut();
finish();
return true;
case R.id.Wall:
Intent intent = new Intent(ProfilePage.this,
Wall.class);
startActivity(intent);
return true;
case R.id.Save:
save_update_button();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
[user=439709]@override[/user]
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Here we need to check if the activity that was triggers was the Image Gallery.
// If it is the requestCode will match the LOAD_IMAGE_RESULTS value.
// If the resultCode is RESULT_OK and there is some data we know that an image was picked.
if (requestCode == LOAD_IMAGE_RESULTS && resultCode == RESULT_OK && data != null) {
// Let's read picked image data - its URI
Uri pickedImage = data.getData();
// Let's read picked image path using content resolver
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
// Now we need to set the GUI ImageView data with data read from the picked file.
image.setImageBitmap(BitmapFactory.decodeFile(imagePath));
// At the end remember to close the cursor or you will end with the RuntimeException!
cursor.close();
}}}
[\CODE]
When I import "uri" for my on activity results at the end of my code I get a bunch of errors for everything I'm doing with parse. I been searching and trying different image picker tutorials and always end up with same results. I've checked out parse.com but only see info on saving images from the drawable folder. If I can get the image picker to work I'm pretty sure I can figure out how to save it to parse.com.
Sent from my Nexus 6 using XDA Free mobile app

No Empty constructor ? cant seem to figure out.

so i have been working on an app for a while now but now my code is crashing due to no empty constructor.
but i have no more idea how i should fix this.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Code:
package com.spacewizz.powersavelauncher;
import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class ChooserAppsSettings extends LinearLayout {
private static final int CAPACITY = 6;
private static final String KEY_LIST[] = { "1", "2", "3", "4", "5", "6"};
private static final String HENABLED_KEY = "com.spacewizz.powersavelauncher.HENABLED";
private static final String KEY_APPNAME_KEY[] = {
"com.spacewizz.powersavelauncher.APP1", "com.spacewizz.powersavelauncher.APP2",
"com.spacewizz.powersavelauncher.APP3", "com.spacewizz.powersavelauncher.APP4",
"com.spacewizz.powersavelauncher.APP5", "com.spacewizz.powersavelauncher.APP6"};
private static final String KEY_INTENTNAME_KEY[] = {
"com.spacewizz.powersavelauncher.INTENT1", "com.spacewizz.powersavelauncher.INTENT2",
"com.spacewizz.powersavelauncher.INTENT3", "com.spacewizz.powersavelauncher.INTENT4",
"com.spacewizz.powersavelauncher.INTENT5", "com.spacewizz.powersavelauncher.INTENT6"};
private static final String KEY_SETTINGS = "com.spacewizz.powersavelauncher.SETTINGS";
private static final String VIEW_MODE_KEY = "com.spacewizz.powersavelauncher.VIEW_MODE_KEY";
private static final String KEY_APPNAME[] = { "ZAPP1", "ZAPP2", "ZAPP3", "ZAPP4", "ZAPP5", "ZAPP6" };
private static final String HORIZONTAL_KEY = "com.spacewizz.powersavelauncher.HORIZONTAL";
private static final String KEY_APPINTENT[] = { "XAPP1", "XAPP2", "XAPP3", "XAPP4", "XAPP5", "XAPP6" };
private static final String KEY_INTENT_ACTION[] = { "IAPP1", "IAPP2",
"IAPP3", "IAPP4", "IAPP5", "IAPP6" };
private ArrayList<String> INSTALLED_PACKAGE = new ArrayList<String>();
private ArrayList<String> APP_NAME = new ArrayList<String>();
private ArrayList<Intent> LAUNCH_ACTIVITY = new ArrayList<Intent>();
private ArrayList<Drawable> APP_ICONS = new ArrayList<Drawable>();
private ArrayList<String> APPS_SHORTCUT = new ArrayList<String>(CAPACITY);
private ArrayAdapter<String> APPS_SHORTCUT_ADAPTER;
private String OPTIONS[] = { "Remove shortcut" };
private String APP_NAMES[] = new String[CAPACITY];
private String OLD_LIST_NAME, NEW_LIST_NAME, INTENT;
private String MODES[] = { "Icon + Label", "Icon only", "Label only",
"Icon + Label (Vertical)" };
Intent mIntent;
boolean horizontal, henabled;
SharedPreferences sp;
ArrayAdapter<String> mSpinnerAdapter;
SharedPreferences.Editor spe;
private Spinner VIEW_MODES;
private ListView APPSLISTVIEW;
private TextView ViewSettingsLabel, AppsListLabel;
private CheckBox HorizontalScroll;
private Context mContext;
int mSpinnerPos;
private LinearLayout THESETTINGS;
private Button mSettings, mDoneSettings;
private ProgressDialog dialog;
private ScrollView mSettingsView;
private Dialog mSettingsDialog;
private WindowManager.LayoutParams WMLP;
public ChooserAppsSettings(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
this.mContext = context;
dialog = new ProgressDialog(mContext);
dialog.setTitle("Please wait...");
dialog.setMessage("Loading installed applications...");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
henabled = getCBState();
setOrientation(LinearLayout.VERTICAL);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
LinearLayout.LayoutParams TVLP = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
TVLP.gravity = Gravity.CENTER_VERTICAL;
mSpinnerPos = getSpinnerPos();
mSettings = new Button(mContext);
mSettings.setText("Settings");
mSettings.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
mDoneSettings = new Button(mContext);
mDoneSettings.setText("Done!");
mDoneSettings.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
THESETTINGS = new LinearLayout(mContext);
THESETTINGS.setOrientation(LinearLayout.VERTICAL);
THESETTINGS.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
mSettingsView = new ScrollView(mContext);
mSettingsView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
VIEW_MODES = new Spinner(mContext);
VIEW_MODES.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
mSpinnerAdapter = new ArrayAdapter<String>(mContext,
android.R.layout.simple_spinner_item, MODES);
mSpinnerAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
VIEW_MODES.setAdapter(mSpinnerAdapter);
VIEW_MODES.setSelection(mSpinnerPos);
LinearLayout.LayoutParams ColorLL = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 50);
ColorLL.bottomMargin = 30;
ColorLL.topMargin = 20;
ColorLL.leftMargin = 50;
ColorLL.rightMargin = 50;
ViewSettingsLabel = new TextView(mContext);
AppsListLabel = new TextView(mContext);
ViewSettingsLabel.setLayoutParams(TVLP);
AppsListLabel.setLayoutParams(TVLP);
ViewSettingsLabel.setText("Display Options");
AppsListLabel.setText("App Shortcuts List: ");
ViewSettingsLabel.setBackgroundResource(android.R.drawable.title_bar);
AppsListLabel.setBackgroundResource(android.R.drawable.title_bar);
ViewSettingsLabel.setGravity(Gravity.CENTER);
HorizontalScroll = new CheckBox(mContext);
HorizontalScroll.setLayoutParams(TVLP);
HorizontalScroll.setText("Horizontal Scroll (Icon only)");
HorizontalScroll.setEnabled(horizontal);
HorizontalScroll.setChecked(henabled);
APPSLISTVIEW = new ListView(mContext);
APPSLISTVIEW.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
addView(APPSLISTVIEW);
mSettingsDialog = new Dialog(mContext);
mSettingsDialog.setTitle("Settings");
mSettingsDialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
mSettingsDialog.setContentView(mSettingsView);
mSettingsDialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
android.R.drawable.ic_menu_manage);
WMLP = new WindowManager.LayoutParams();
WMLP.copyFrom(mSettingsDialog.getWindow().getAttributes());
WMLP.width = WindowManager.LayoutParams.MATCH_PARENT;
WMLP.height = WindowManager.LayoutParams.WRAP_CONTENT;
for (int i = 1; i <= CAPACITY; i++) {
APPS_SHORTCUT.add("Application " + String.valueOf(i));
}
APPS_SHORTCUT_ADAPTER = new ArrayAdapter<String>(context,
android.R.layout.simple_list_item_1, APPS_SHORTCUT);
dialog.show();
preloadInstalledApplications Preload = new preloadInstalledApplications();
Preload.execute(02, 23, 1997);
setHorizontalScrollListener();
//setViewModeOnItemSelectedListener();
setAppListViewOnClickListener();
setApplistViewOnLongClickListener();
//setmSettingsOnClickListener();
//setmDoneSettingsOnClickListener();
loadList();
refreshList();
}
private boolean getCBState() {
sp = PreferenceManager.getDefaultSharedPreferences(mContext);
return sp.getBoolean(HENABLED_KEY, false);
}
private void saveCBState(boolean state) {
openSPE();
spe.putBoolean(HENABLED_KEY, state);
commitSPE();
}
private boolean getHorizontal() {
sp = PreferenceManager.getDefaultSharedPreferences(mContext);
return sp.getBoolean(HORIZONTAL_KEY, false);
}
private void setHorizontalScrollListener() {
// TODO Auto-generated method stub
HorizontalScroll
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (HorizontalScroll.isChecked()) {
saveCBState(HorizontalScroll.isChecked());
} else {
saveCBState(HorizontalScroll.isChecked());
}
}
});
}
private void setmDoneSettingsOnClickListener() {
// TODO Auto-generated method stub
mDoneSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (mSettingsDialog.isShowing()) {
mSettingsDialog.dismiss();
}
}
});
}
private void setmSettingsOnClickListener() {
// TODO Auto-generated method stub
mSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mSettingsDialog.show();
mSettingsDialog.getWindow().setAttributes(WMLP);
}
});
}
private void setViewModeOnItemSelectedListener() {
// TODO Auto-generated method stub
VIEW_MODES.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
mSpinnerPos = arg2;
int MODE = mSpinnerPos;
VIEW_MODES.setSelection(mSpinnerPos);
saveSpinnerPos(mSpinnerPos);
if (mSpinnerPos == 1) {
horizontal = true;
henabled = HorizontalScroll.isChecked();
if (henabled) {
MODE = 100;
} else {
MODE = mSpinnerPos;
}
} else {
horizontal = false;
henabled = false;
}
sendViewModeSettings(MODE);
HorizontalScroll.setEnabled(horizontal);
openSPE();
spe.putBoolean(HORIZONTAL_KEY, horizontal);
commitSPE();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
VIEW_MODES.setSelection(mSpinnerPos);
}
});
}
private void saveSpinnerPos(int pos) {
sp = PreferenceManager.getDefaultSharedPreferences(getContext());
spe = sp.edit();
spe.putInt(VIEW_MODE_KEY, pos);
spe.commit();
}
private int getSpinnerPos() {
sp = PreferenceManager.getDefaultSharedPreferences(getContext());
return sp.getInt(VIEW_MODE_KEY, 0);
}
private void sendViewModeSettings(int mode) {
mIntent = new Intent();
mIntent.setAction(KEY_SETTINGS);
mIntent.putExtra(VIEW_MODE_KEY, mode);
mContext.sendBroadcast(mIntent);
}
private void setApplistViewOnLongClickListener() {
// TODO Auto-generated method stub
APPSLISTVIEW.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
final ListAdapter OPTIONSMENU = new ArrayAdapter<String>(
mContext, android.R.layout.simple_list_item_1, OPTIONS);
new AlertDialog.Builder(mContext)
.setTitle("Options")
.setIcon(android.R.drawable.ic_dialog_info)
.setAdapter(OPTIONSMENU,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
switch (which) {
case 0:
String NEW_ITEM = "Application "
+ String.valueOf(arg2 + 1)
+ " (Not on SystemUI)";
APPS_SHORTCUT.remove(arg2);
APPS_SHORTCUT.add(arg2, NEW_ITEM);
sendDeleteCommand(arg2);
APP_NAMES[arg2] = APPS_SHORTCUT
.get(arg2);
saveList(arg2);
refreshList();
break;
}
}
}).show();
return false;
}
});
}
private void setAppListViewOnClickListener() {
// TODO Auto-generated method stub
APPSLISTVIEW.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
final ListAdapter ADAPTER = new ArrayAdapter<String>(mContext,
android.R.layout.simple_list_item_1, APP_NAME);
new AlertDialog.Builder(mContext)
.setTitle("Select Application")
.setIcon(android.R.drawable.ic_dialog_alert)
.setAdapter(ADAPTER,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
Toast.makeText(
getContext(),
"Application "
+ String.valueOf(arg2 + 1)
+ " selected: "
+ ADAPTER
.getItem(which)
.toString(),
Toast.LENGTH_SHORT).show();
OLD_LIST_NAME = APPS_SHORTCUT.get(arg2);
NEW_LIST_NAME = ADAPTER.getItem(which)
.toString();
if (OLD_LIST_NAME != NEW_LIST_NAME) {
APPS_SHORTCUT.remove(arg2);
String NEW_ITEM = ADAPTER.getItem(
which).toString();
APPS_SHORTCUT.add(arg2, NEW_ITEM);
if (LAUNCH_ACTIVITY.get(which) != null) {
INTENT = INSTALLED_PACKAGE
.get(which);
} else {
INTENT = "null";
}
refreshToBePassed(arg2, NEW_ITEM,
INTENT);
}
saveList(arg2);
refreshList();
}
}).show();
}
});
}
private void refreshList() {
APPS_SHORTCUT_ADAPTER = new ArrayAdapter<String>(mContext,
android.R.layout.simple_list_item_1, APPS_SHORTCUT);
APPSLISTVIEW.setAdapter(APPS_SHORTCUT_ADAPTER);
}
private void refreshToBePassed(int position, String APP, String mINTENT) {
APP_NAMES[position] = APP;
KEY_APPNAME[position] = APPS_SHORTCUT_ADAPTER.getItem(position);
KEY_APPINTENT[position] = mINTENT;
mIntent = new Intent();
mIntent.setAction(KEY_INTENT_ACTION[position]);
mIntent.putExtra(KEY_APPNAME_KEY[position], KEY_APPNAME[position]);
mIntent.putExtra(KEY_INTENTNAME_KEY[position], KEY_APPINTENT[position]);
mContext.sendBroadcast(mIntent);
}
private void saveList(int position) {
sp = PreferenceManager.getDefaultSharedPreferences(getContext());
spe = sp.edit();
spe.putString(KEY_LIST[position], APP_NAMES[position]);
spe.commit();
}
private void loadList() {
// TODO Auto-generated method stub
sp = PreferenceManager.getDefaultSharedPreferences(getContext());
APPS_SHORTCUT.clear();
for (int x = 0; x < CAPACITY; x++) {
APP_NAMES[x] = sp.getString(KEY_LIST[x],
"Application " + String.valueOf((x + 1)));
APPS_SHORTCUT.add(APP_NAMES[x]);
}
}
private void sendDeleteCommand(int position) {
KEY_APPNAME[position] = "DELETE";
KEY_APPINTENT[position] = "DELETE";
mIntent = new Intent();
mIntent.setAction(KEY_INTENT_ACTION[position]);
mIntent.putExtra(KEY_APPNAME_KEY[position], KEY_APPNAME[position]);
mIntent.putExtra(KEY_INTENTNAME_KEY[position], KEY_APPINTENT[position]);
mContext.sendBroadcast(mIntent);
}
private void openSPE() {
sp = PreferenceManager.getDefaultSharedPreferences(mContext);
spe = sp.edit();
}
private void commitSPE() {
spe.commit();
}
private class preloadInstalledApplications extends
AsyncTask<Integer, Void, Void> {
@Override
protected Void doInBackground(Integer... params) {
// TODO Auto-generated method stub
final PackageManager PM = mContext.getPackageManager();
List<ApplicationInfo> PACKAGES = PM
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo PACKAGE_INFO : PACKAGES) {
if (PM.getLaunchIntentForPackage(PACKAGE_INFO.packageName) != null) {
INSTALLED_PACKAGE.add(PACKAGE_INFO.packageName);
LAUNCH_ACTIVITY
.add(PM.getLaunchIntentForPackage(PACKAGE_INFO.packageName));
APP_ICONS.add(PM.getApplicationIcon(PACKAGE_INFO));
APP_NAME.add(PM.getApplicationLabel(PACKAGE_INFO)
.toString());
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialog.dismiss();
}
}
}
anyone knows how to fix?
thanks
This' to put it inns nutshell
haaaroldb said:
This' to put it inns nutshell
Click to expand...
Click to collapse
I am sorry i don't understand. can you explain ?
I am not sure, but your class might be missing constructor
more info: http://www.javatpoint.com/constructor
For some reason it says that it needs and Empty constructor.
Type inside ChooserAppSettings class:
Code:
public ChooserAppSettings(){
}
This may fix it. I am not sure though why it needs the empty constructor. What class is your ChooserAppSettings extending or implementing??
Can you show all the logcat messages?
@mmdeveloper said:
For some reason it says that it needs and Empty constructor.
Type inside ChooserAppSettings class:
Code:
public ChooserAppSettings(){
}
This may fix it. I am not sure though why it needs the empty constructor. What class is your ChooserAppSettings extending or implementing??
Can you show all the logcat messages?
Click to expand...
Click to collapse
Linearlayout.
Tried the above but didnt worked
Try adding these:
Code:
public ChooserAppSettings(Context context){
super(context);
}
public ChooserAppSettings(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
}
Issue solved.
was a stupid fault of myself xD
typo at launching the java file

Categories

Resources