Hi all I am using a splash activity for first time or he is logged out from my app. But this appear frequently on Samsung galaxy S2. This my activity onCreate() method code
private static EditText serverIP = null;
String mMDCServerIP = "";
String skipSplashScreenStatus = null;
String mSplashScreenRunningStatus = null;
String mDeniedStatusFromServer = null;
public void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
/** Get the MDC IP **/
Log.d("splash","1111111111111111");
skipSplashScreenStatus = Config.getSetting(getApplicationContext(),"SPLASHSTATUS");
mSplashScreenRunningStatus = Config.getSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS");
mDeniedStatusFromServer = Config.getSetting(getApplicationContext(),"DENYSTATUS");
if(skipSplashScreenStatus == null || skipSplashScreenStatus.length() == 0)
{
Config.setSetting(getApplicationContext(),"DENYSTATUS","false");
}
/** If SPLASHSTATUS does not exist then store the SPLASHSTATUS as false**/
if(skipSplashScreenStatus == null || skipSplashScreenStatus.length() == 0)
{
Config.setSetting(getApplicationContext(),"SPLASHSTATUS","false");
}
if(mSplashScreenRunningStatus == null || mSplashScreenRunningStatus.length() == 0)
{
Config.setSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS","yes");
}
Log.d("splash","222222222222222222");
Log.d("splash","skipSplashScreenStatus : "+skipSplashScreenStatus);
skipSplashScreenStatus = Config.getSetting(getApplicationContext(),"SPLASHSTATUS");
if(skipSplashScreenStatus!= null && skipSplashScreenStatus.equalsIgnoreCase("yes"))
{
Log.d("splash","inside if condition");
skipSplashScreen();
}
else{
Log.d("splash","inside else condition");
setContentView(R.layout.splash_screen);
Log.d("SPLASH","33333333333333");
serverIP = (EditText) findViewById(R.id.splash_server_ip);
/** Get the MDC IP **/
mMDCServerIP = Config.getSetting(getApplicationContext(),"IPADDR");
/** If MDC IP does not exist then store the IP as 0.0.0.0**/
if(mMDCServerIP == null || mMDCServerIP.length() == 0)
{
Config.setSetting(getApplicationContext(),"IPADDR","0.0.0.0");
}
serverIP.setOnEditorActionListener(new EditText.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Config.setSetting(getApplicationContext(),"SPLASHSTATUS","yes");
Config.setSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS","no");
skipSplashScreen();
}}}}
Here is the code for skipSplashScreen();
private void skipSplashScreen()
{
try{
Log.d("splash","inside skipSplashScreen 111");
CommandHandler.mStopSendingKeepAlive = false;
Log.d("splash","inside skipSplashScreen 222");
startActivity(new Intent(getApplicationContext() ,SecondTest.class));
}
catch(Exception e)
{
Log.d("splash","Exception in skipSplashScreen 333");
Log.d("splash",e.getMessage());
}
}
Once i dig more into code it seems control is skipSplashScreen() method but not starting second activity. May i know what can be the reason.
Try this, when starting the activity, use Activity.this instead of getApplicationContext()
private void skipSplashScreen()
{
try{
Log.d("splash","inside skipSplashScreen 111");
CommandHandler.mStopSendingKeepAlive = false;
Log.d("splash","inside skipSplashScreen 222");
startActivity(new Intent(SplashScreen.this ,SecondTest.class));
}
catch(Exception e)
{
Log.d("splash","Exception in skipSplashScreen 333");
Log.d("splash",e.getMessage());
}
}
Related
I am making a default phone call. Everything works well till I made a call to the switchboard operator.
In this kind of call, the phone says: "Press 1 to do A, press 2 to do B".
I did some research for hours but couldn't find one...
I did try this code, but it doesn't work.
keyPressed(KeyEvent.KEYCODE_1); // when press key 1
private void keyPressed(int keyCode) {
....
Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + keyCode));
startActivity(I);
....
playTone(ToneGenerator.TONE_DTMF_1, TONE_LENGTH_INFINITE);
}
Big thanks for any of your suggestions!
Added 1:
I am using InCallService like this:
class CallService : InCallService() {
private var isShowEnded = true
override fun onCallAdded(call: Call) {
super.onCallAdded(call)
OngoingCall().setCall(call)
CallActivity.getInstance().start(this, call)
isShowEnded = false
}
override fun onCallRemoved(call: Call) {
super.onCallRemoved(call)
OngoingCall().setCall(null)
}
}
and OngoingCall:
public class OngoingCall {
public static BehaviorSubject<Integer> state = BehaviorSubject.create();
private static Call sCall;
public Call getsCall() {
return sCall;
}
#RequiresApi(api = Build.VERSION_CODES.M)
private Object callback = new Call.Callback() {
#Override
public void onStateChanged(Call call, int newState) {
super.onStateChanged(call, newState);
state.onNext(newState);
}
};
#RequiresApi(api = Build.VERSION_CODES.M)
public final void setCall(#Nullable Call value) {
if (sCall != null) {
sCall.unregisterCallback((Call.Callback) callback);
}
if (value != null) {
value.registerCallback((Call.Callback) callback);
state.onNext(value.getState());
}
sCall = value;
}
#RequiresApi(api = Build.VERSION_CODES.M)
public void answer() {
if (sCall != null) {
assert sCall != null;
sCall.answer(VideoProfile.STATE_AUDIO_ONLY);
}
}
#RequiresApi(api = Build.VERSION_CODES.M)
public void hold(boolean hold) {
if (sCall != null) {
if (hold) sCall.hold();
else sCall.unhold();
}
}
#RequiresApi(api = Build.VERSION_CODES.M)
public void addCall(Call call) {
if (sCall != null) {
sCall.conference(call);
}
}
#RequiresApi(api = Build.VERSION_CODES.M)
public void hangup() {
if (sCall != null) {
sCall.disconnect();
}
}
}
And then I tried this when pressing keyboard:
mTrueCallerOngoingCall.getsCall().playDtmfTone((char) tone); // inside playTone()
But it's still not working :(
Update 2:
I have fixed my adding this method:
private char getChar(int tone) {
if (tone == 0) return '0';
else if (tone == 1) return '1';
else if (tone == 2) return '2';
else if (tone == 3) return '3';
else if (tone == 4) return '4';
else if (tone == 5) return '5';
else if (tone == 6) return '6';
else if (tone == 7) return '7';
else if (tone == 8) return '8';
else if (tone == 9) return '9';
else if (tone == 10) return '*';
else return '#';
}
and change from my above code to
mTrueCallerOngoingCall.getsCall().playDtmfTone(getChar(tone));
mTrueCallerOngoingCall.getsCall().stopDtmfTone();
It is .Hope can help you.
call.playDtmfTone(char);
The call PATH:
android.telecom.Call;
From: Any Class extends InCallService.
In Method: onCallAdded(call);
I am able to Display Hint to the Spinner through the layout.I want to achieve the spinner field to be clear after the click in Submit button and should display hint. I am using spinner_district.setSelection(1); it is displaying the array of value 1 but i want to display hint not any value of spinner.
for clearing field
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
// spinner_district.setSelection(1);
function
public void onClick(View v) {
switch (v.getId()) {
case R.id.send_school_registration_form:
if (isConnected()) {
String name = registerSchoolName.getText().toString();
String address = registerSchoolAddress.getText().toString();
String phone = registerSchoolPhone.getText().toString();
String email = registerSchoolEmail.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-]+#[a-z]+\\.+[a-z]+";
String website = registerSchoolWebsite.getText().toString();
String estbdate = schoolEstDate.getText().toString();
String admissionOpen = schoolAdmissionStartDate.getText().toString();
String admissionEnd = schoolAdmissionEndDate.getText().toString();
district = null;
if (spinner_district != null && spinner_district.getSelectedItem() != null) {
district = (String) spinner_district.getSelectedItem();
}
country = null;
if (spinner_country != null && spinner_country.getSelectedItem() != null) {
country = (String) spinner_country.getSelectedItem();
}
institution = null;
if (spinner_institution != null && spinner_institution.getSelectedItem() != null) {
institution = (String) spinner_institution.getSelectedItem();
}
fee = registerSchoolFee.getText().toString();
level = null;
if (spinner_school_level != null && spinner_school_level.getSelectedItem() != null) {
level = (String) spinner_school_level.getSelectedItem();
}
if (addSchoolProgram1.getVisibility() == View.VISIBLE) {
fee1 = registerSchoolFee1.getText().toString();
level1 = null;
if (spinner_school_level1 != null && spinner_school_level1.getSelectedItem() != null) {
level1 = (String) spinner_school_level1.getSelectedItem();
}
}
if (addSchoolProgram2.getVisibility() == View.VISIBLE) {
fee2 = registerSchoolFee2.getText().toString();
level2 = null;
if (spinner_school_level2 != null && spinner_school_level2.getSelectedItem() != null) {
level2 = (String) spinner_school_level2.getSelectedItem();
}
}
if (addSchoolProgram3.getVisibility() == View.VISIBLE) {
fee3 = registerSchoolFee3.getText().toString();
level3 = null;
if (spinner_school_level3 != null && spinner_school_level3.getSelectedItem() != null) {
level3 = (String) spinner_school_level3.getSelectedItem();
}
}
if (addSchoolProgram4.getVisibility() == View.VISIBLE) {
fee4 = registerSchoolFee4.getText().toString();
level4 = null;
if (spinner_school_level4 != null && spinner_school_level4.getSelectedItem() != null) {
level4 = (String) spinner_school_level4.getSelectedItem();
}
}
if (addSchoolProgram5.getVisibility() == View.VISIBLE) {
fee5 = registerSchoolFee5.getText().toString();
level5 = null;
if (spinner_school_level5 != null && spinner_school_level5.getSelectedItem() != null) {
level5 = (String) spinner_school_level5.getSelectedItem();
}
}
if (addSchoolProgram6.getVisibility() == View.VISIBLE) {
fee6 = registerSchoolFee6.getText().toString();
level6 = null;
if (spinner_school_level6 != null && spinner_school_level6.getSelectedItem() != null) {
level6 = (String) spinner_school_level6.getSelectedItem();
}
}
if (addSchoolProgram7.getVisibility() == View.VISIBLE) {
fee7 = registerSchoolFee7.getText().toString();
level7 = null;
if (spinner_school_level7 != null && spinner_school_level7.getSelectedItem() != null) {
level7 = (String) spinner_school_level7.getSelectedItem();
}
}
if (addSchoolProgram8.getVisibility() == View.VISIBLE) {
fee8 = registerSchoolFee8.getText().toString();
level8 = null;
if (spinner_school_level8 != null && spinner_school_level8.getSelectedItem() != null) {
level8 = (String) spinner_school_level8.getSelectedItem();
}
}
if (addSchoolProgram9.getVisibility() == View.VISIBLE) {
fee9 = registerSchoolFee9.getText().toString();
level9 = null;
if (spinner_school_level9 != null && spinner_school_level9.getSelectedItem() != null) {
level9 = (String) spinner_school_level9.getSelectedItem();
}
}
if ((name.matches("")) || (address.matches("")) || (phone.matches("")) || (email.matches("")) || (website.matches("")) || (estbdate.matches("")) || (admissionOpen.matches(""))
|| (admissionEnd.matches("")) || (district.matches("")) || (country.matches("")) || (institution.matches("")) || (fee.matches("")) || (level.matches("")) ||
(schoolLogoUpload.getDrawable() == null)
) {
Toast.makeText(this, "Please fill up all the fields", Toast.LENGTH_LONG).show();
} else {
if ((email.matches(emailPattern)) && ((Patterns.WEB_URL.matcher(website)).matches())) {
Bitmap image = ((BitmapDrawable) schoolLogoUpload.getDrawable()).getBitmap();
new UploadImage(image, name, address, phone, email, website, district, country, institution, estbdate, fee, level, fee1, level1, fee2, level2, fee3, level3, fee4, level4, fee5, level5, fee6, level6, fee7, level7,
fee8, level8, fee9, level9, admissionOpen,
admissionEnd).execute();
} else
Toast.makeText(getApplicationContext(), "Invalid website and email address", Toast.LENGTH_LONG).show();
}
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
// spinner_district.setSelection(1);
//spinner_district.setSelection(1);
Spinner spinner_country, spinner_institution, spinner_school_level, spinner_school_level1, spinner_school_level2, spinner_school_level3, spinner_school_level4,
spinner_school_level5, spinner_school_level6, spinner_school_level7, spinner_school_level8, spinner_school_level9;
} else {
Toast.makeText(this, "Please check your internet connection", Toast.LENGTH_LONG).show();
}
break;
case R.id.cancel_school_registration_form:
this.finish();
break;
case R.id.register_school_logo:
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
break;
case R.id.register_school_estdate:
datePickerDialogSchool.show();
break;
case R.id.school_admission_startDate:
schoolAdmissionStartDatePicker.show();
break;
case R.id.school_admission_end_date:
schoolAdmissionEndDatePicker.show();
break;
case R.id.add_more_school_programs:
if (addMoreSchoolProgram.getVisibility() == View.VISIBLE) {
if (addSchoolProgram9.getVisibility() == View.GONE) {
if (addSchoolProgram8.getVisibility() == View.GONE) {
if (addSchoolProgram7.getVisibility() == View.GONE) {
if (addSchoolProgram6.getVisibility() == View.GONE) {
if (addSchoolProgram5.getVisibility() == View.GONE) {
if (addSchoolProgram4.getVisibility() == View.GONE) {
if (addSchoolProgram3.getVisibility() == View.GONE) {
if (addSchoolProgram2.getVisibility() == View.GONE) {
if (addSchoolProgram1.getVisibility() == View.GONE) {
addSchoolProgram1.setVisibility(View.VISIBLE);
} else
addSchoolProgram2.setVisibility(View.VISIBLE);
} else
addSchoolProgram3.setVisibility(View.VISIBLE);
} else
addSchoolProgram4.setVisibility(View.VISIBLE);
} else
addSchoolProgram5.setVisibility(View.VISIBLE);
} else
addSchoolProgram6.setVisibility(View.VISIBLE);
} else
addSchoolProgram7.setVisibility(View.VISIBLE);
} else
addSchoolProgram8.setVisibility(View.VISIBLE);
} else
addSchoolProgram9.setVisibility(View.VISIBLE);
} else
addMoreSchoolProgram.setVisibility(View.GONE);
}
break;
case R.id.register_school_email:
}
}
How can resetting to spinner be done with providing hint not the
spinner values??
you can use following code to solve the issue
admissionEnd).execute();
registerSchoolName.setText("");
registerSchoolAddress.setText("");
registerSchoolPhone.setText("");
registerSchoolEmail.setText("");
registerSchoolWebsite.setText("");
registerSchoolFee.setText("");
registerSchoolFee1.setText("");
registerSchoolFee2.setText("");
registerSchoolFee3.setText("");
registerSchoolFee3.setText("");
registerSchoolFee4.setText("");
registerSchoolFee5.setText("");
registerSchoolFee6.setText("");
registerSchoolFee7.setText("");
registerSchoolFee8.setText("");
registerSchoolFee9.setText("");
schoolEstDate.setText("");
schoolAdmissionStartDate.setText("");
schoolAdmissionEndDate.setText("");
// spinner_district.setAdapter(null);
spinner_district.setPrompt("District");
spinner_district.setSelection(0);
use setPrompt and setSelection
when i try to get a true/false value from a different class it seems that it is defaulting to false. here are the snippets of my code that should be the problem. the first snippet is the class i'm getting the values from, the second one is the one that is requesting that information. and at the bottom of the second class is the function that should make the class render on the apps screen but seems to not work at all every time. you should be able to understand my coding cause i practice the art of commenting profusely.
private boolean AddProb;
private boolean SubProb;
private boolean MultiProb;
private boolean DivisProb;
public int ANum = 0;
public int SNum;
public int MNum;
public int DNum;
//ProblemSelector PS = new ProblemSelector();
CheckBox checkbox1, checkbox2, checkbox3, checkbox4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_problem_selector);
checkbox1 = (CheckBox) findViewById(R.id.checkBox1);
checkbox2 = (CheckBox) findViewById(R.id.checkBox2);
checkbox3 = (CheckBox) findViewById(R.id.checkBox3);
checkbox4 = (CheckBox) findViewById(R.id.checkBox4);
/** waits for checkbox1 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
AddProb = true;
Toast.makeText(getBaseContext(), "Addition: True", Toast.LENGTH_SHORT).show();
System.out.println("Addition: True");
if(AddProb) {
Log.d("ProblemSelector.java","AddProb did successfully change to true");
} else if(!AddProb){
Log.d("ProblemSelector.java","AddProb did not successfully change to true");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 50-56");
}
} else {
AddProb = false;
Toast.makeText(getBaseContext(), "Addition: False", Toast.LENGTH_SHORT).show();
System.out.println("Addition: False");
if(AddProb) {
Log.d("ProblemSelector.java","AddProb did successfully change to false");
} else if(!AddProb) {
Log.d("ProblemSelector.java","AddProb did not successfully change to false");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 61-67");
}
}
}
});
/** waits for checkbox2 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
checkbox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
SubProb = true;
Toast.makeText(getBaseContext(), "Subtraction: True", Toast.LENGTH_SHORT).show();
System.out.println("Subtraction: True");
if(SubProb) {
Log.d("ProblemSelector.java","SubProb did successfully change to true");
} else if(!SubProb) {
Log.d("ProblemSelector.java","SubProb did not successfully change to true");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 82-88");
}
if(AddProb == false) {
SNum = 0;
}
else if(AddProb == true) {
SNum = 1;
}
} else {
SubProb = false;
Toast.makeText(getBaseContext(), "Subtraction: False", Toast.LENGTH_SHORT).show();
System.out.println("Subtraction: False");
if(SubProb) {
Log.d("ProblemSelector.java","SubProb did successfully change to false");
} else if(!SubProb) {
Log.d("ProblemSelector.java","SubProb did not successfully change to false");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 99-105");
}
}
}
});
/** waits for checkbox3 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
checkbox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
MultiProb = true;
Toast.makeText(getBaseContext(), "Multiplication: True", Toast.LENGTH_SHORT).show();
System.out.println("Multiplication: True");
if(MultiProb) {
Log.d("ProblemSelector.java","MultiProb did successfully change to true");
} else if(!MultiProb) {
Log.d("ProblemSelector.java","MultiProb did not successfully change to true");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 120-126");
}
if(AddProb == false && SubProb == false) {
MNum = 0;
}
else if(AddProb == true && SubProb == false || AddProb == false && SubProb == true) {
MNum = 1;
}
else if(AddProb == true && SubProb == true) {
MNum = 2;
}
} else {
MultiProb = false;
Toast.makeText(getBaseContext(), "Multiplication: False", Toast.LENGTH_SHORT).show();
System.out.println("Multiplication: False");
if(MultiProb) {
Log.d("ProblemSelector.java","MultiProb did successfully change to false");
} else if(!MultiProb) {
Log.d("ProblemSelector.java","MultiProb did not successfully change to false");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 140-146");
}
}
}
});
/** waits for checkbox4 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
/** and determines if the value of the boolean for this function has changed successfully or not **/
checkbox4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
DivisProb = true;
Toast.makeText(getBaseContext(), "Division: True", Toast.LENGTH_SHORT).show();
System.out.println("Division: True");
if(DivisProb) {
Log.d("ProblemSelector.java","DivisProb did successfully change to true");
} else if(!DivisProb) {
Log.d("ProblemSelector.java","DivisProb did not successfully change to true");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 162-168");
}
if(AddProb == false && SubProb == false && MultiProb == false) {
DNum = 0;
}
else if(AddProb == true && SubProb == false && MultiProb == false || AddProb == false && SubProb == true && MultiProb == false || AddProb == false && SubProb == false && MultiProb == true) {
DNum = 1;
}
else if(AddProb == true && SubProb == true && MultiProb == false || AddProb == false && SubProb == true && MultiProb == true || AddProb == true && SubProb == false && MultiProb == true) {
DNum = 2;
}
else if(AddProb == true && SubProb == true && MultiProb == true) {
DNum = 3;
}
} else {
DivisProb = false;
Toast.makeText(getBaseContext(), "Division: False", Toast.LENGTH_SHORT).show();
System.out.println("Division: False");
if(DivisProb) {
Log.d("ProblemSelector.java","DivisProb did successfully change to false");
} else if(!DivisProb) {
Log.d("ProblemSelector.java","DivisProb did not successfully change to false");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 184-189");
}
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_problem_selector, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/** this is called when the user hits the continue button **/
public void DifficultyMenu(View view) {
String S1 = String.valueOf(AddProb);
Log.d("ProblemSelector.java","AddProb: " + S1);
Intent DifficultyView = new Intent(this, DifficultyMenu.class);
//DifficultyView.putExtra("addProb", PS.AddProb);
//DifficultyView.putExtra("subProb", PS.SubProb);
//DifficultyView.putExtra("multiProb", PS.MultiProb);
//DifficultyView.putExtra("divisProb", PS.DivisProb);
startActivity(DifficultyView);
}
/** this converts the 1st version bools to 2nd version bools and outputs the values to the command line **/
public boolean AddP = AddProb;
public boolean SubP = SubProb;
public boolean MultiP = MultiProb;
public boolean DivisP = DivisProb;
}
here is the second class.
private boolean AddP = PS.AddP;
private boolean SubP = PS.SubP;
private boolean MultiP = PS.MultiP;
private boolean DivisP = PS.DivisP;
private int ANum = PS.ANum;
private int SNum = PS.SNum;
private int MNum = PS.MNum;
private int DNum = PS.DNum;
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_difficulty_menu);
// here you'll retrieve the data sent...you can google how to do that.
// get the list view
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
// List view Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// List view Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
// List view Group collapsed listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
// List view on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(
getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT)
.show();
/** converts the selected number in the expandable list to a usable integer variable **/
/** also detects if a Difficulty has been selected for each for of problem to practice **/
/** also gives an error to debug console level if something unexpected has happened **/
if(listDataHeader.get(groupPosition).equals("AdditionDifficulty")) {
String St1 = listDataHeader.get(childPosition);
int AddDiff = Integer.parseInt(St1);
if(PS.AddP) {
AChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 123 : for some reason this seems to have happened");
}
}
else if(listDataHeader.get(groupPosition).equals("SubtractionDifficulty")) {
String St2 = listDataHeader.get(childPosition);
int SubDiff = Integer.parseInt(St2);
if(PS.SubP) {
SChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 132 : for some reason this seems to have happened");
}
}
else if(listDataHeader.get(groupPosition).equals("MultiplicationDifficulty")) {
String St3 = listDataHeader.get(childPosition);
int MultiDIff = Integer.parseInt(St3);
if(PS.MultiP) {
MChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 141 : for some reason this seems to have happened");
}
}
else if(listDataHeader.get(groupPosition).equals("DivisionDifficulty")) {
String St4 = listDataHeader.get(childPosition);
int DivisDiff = Integer.parseInt(St4);
if(PS.DivisP) {
DChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 150 : for some reason this seems to have happened");
}
}
else {
Log.e("DifficultyMenu.java","could not parse a group position when user selected a field");
}
return false;
}
});
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<>();
listDataChild = new HashMap<>();
// Adding child data
if(AddP) { listDataHeader.add("AdditionDifficulty"); }
if(SubP) { listDataHeader.add("SubtractionDifficulty"); }
if(MultiP) { listDataHeader.add("MultiplicationDifficulty"); }
if(DivisP) { listDataHeader.add("DivisionDifficulty"); }
System.out.println(listDataHeader);
/** this removes fields that the user has not selected to practice **/
// if(!PS.AddProb) { listDataHeader.remove("AdditionDifficulty"); }
// if(!PS.SubProb) { listDataHeader.remove("SubtractionDifficulty"); }
// if(!PS.MultiProb) { listDataHeader.remove("MultiplicationDifficulty"); }
// if(!PS.DivisProb) { listDataHeader.remove("DivisionDifficulty"); }
// Adding child data
List<String> AdditionDifficulty = new ArrayList<>();
while (true) {
if (T1 < 11) {
String S1 = Integer.toString(T1);
AdditionDifficulty.add(S1);
T1++;
} else {
break;
}
}
List<String> SubtractionDifficulty = new ArrayList<>();
while (true) {
if (T2 < 11) {
String S2 = Integer.toString(T2);
SubtractionDifficulty.add(S2);
T2++;
} else {
break;
}
}
List<String> MultiplicationDifficulty = new ArrayList<>();
while (true) {
if (T3 < 11) {
String S3 = Integer.toString(T3);
MultiplicationDifficulty.add(S3);
T3++;
} else {
break;
}
}
List<String> DivisionDifficulty = new ArrayList<>();
while (true) {
if (T4 < 11) {
String S4 = Integer.toString(T4);
DivisionDifficulty.add(S4);
T4++;
} else {
break;
}
}
/** this draws out the Expandable lists **/
if(AddP) {
listDataChild.put(listDataHeader.get(ANum), AdditionDifficulty);
} else {
Log.d("DifficultyMenu.java","Something went wrong at line: 230");
}
if(SubP) {
listDataChild.put(listDataHeader.get(SNum), SubtractionDifficulty);
} else {
Log.d("DifficultyMenu.java","Something went wrong at line: 231");
}
if(MultiP) {
listDataChild.put(listDataHeader.get(MNum), MultiplicationDifficulty);
} else {Log.d("DifficultyMenu.java","Something went wrong at line: 232");
}
if(DivisP) {
listDataChild.put(listDataHeader.get(DNum), DivisionDifficulty);
} else {Log.d("DifficultyMenu.java","Something went wrong at line: 233");
}
}
How to write all writeCharacteristics in a loop in ble in android.code is as follows
in this method i pass 3 writecharacteristic() and only one is write and others are ignored.
if (beartoggle.isChecked()) {
if (mDeviceLight.equalsIgnoreCase("on") && mDeviceAlarm.equalsIgnoreCase("on")) {
byte[] val = {1};
if (check_port_1 == 1) {
mBluetoothLeService.writeCharacteristic(val, 1);
}
if (check_port_2 == 1) {
mBluetoothLeService.writeCharacteristic(val, 2);
}
if (find_me == 1) {
mBluetoothLeService.writeCharacteristic(val, 3);
}
}
}
and someone is saying use public void onReliableWriteCompleted() and check if port1 is written then go to port2 and then findme. This method will help me, if yes then how ? Please send me clear details and following is my writeCharacteristic()
public boolean writeCharacteristic(byte value[], int type) {
//check mBluetoothGatt is available
if (mBluetoothGatt == null) {
Log.e(TAG, "lost connection");
return false;
}
BluetoothGattService Service = mBluetoothGatt.getService(UUID_SIMPLESERVICE);
if (Service == null) {
Log.e(TAG, "service not found!");
return false;
}
BluetoothGattCharacteristic charac1 = null;
BluetoothGattCharacteristic charac2 = null;
BluetoothGattCharacteristic charac3 = null;
boolean status1 = false, status2 = false, status3 = false;
Log.v("___TYPE___", "________1______________" + (type == 1));
Log.v("___TYPE___", "________2______________" + (type == 2));
Log.v("___TYPE___", "________3______________" + (type == 3));
onReliableWriteCompleted(status1);
onReliableWriteCompleted(status2);
onReliableWriteCompleted(status3);
if (type == 1) {
charac1 = Service.getCharacteristic(UUID_PORT1);
charac1.setValue(value);
status1 = mBluetoothGatt.writeCharacteristic(charac1);
Log.v("________BLESERVICE____", "___WRITE CHARATERISTICS STATUS:_________" + status1);
onReliableWriteCompleted(status1);
} else if (type == 2) {
charac2 = Service.getCharacteristic(UUID_PORT2);
charac2.setValue(value);
status2 = mBluetoothGatt.writeCharacteristic(charac2);
onReliableWriteCompleted(status2);
Log.v("________BLESERVICE_______", "___WRITE CHARACTERISTICS STATUS_______" + status2);
} else if (type == 3) {
charac3 = Service.getCharacteristic(UUID_FINDME);
charac3.setValue(value);
status3 = mBluetoothGatt.writeCharacteristic(charac3);
onReliableWriteCompleted(status3);
Log.v("__________BLESERVICE_________", "___WRITE CHARACTERISTICS STATUS_____" + status3);
}
if (charac1 == null && charac2 == null && charac3 == null) {
Log.e(TAG, "char not found!");
return false;
}
Log.v("___TYPE___", "______________________" + type);
return status1 && status2 && status3;
}
call BluetoothLeService.getSupportedGattServices(), you will get a list of services. Iterate through it and call BluetoothGattService.getCharacteristics(). You will again get a list, you can iterate through it.
For more info, you can refer this
i am doing an application that needs a special keyboard and i can get the text into a edit text by pressing the keys.
public class SecondActivity extends Activity implements
OnKeyboardActionListener, OnKeyListener {
private static final String TAG = SecondActivity.class.getName();
private EditText editText1, editText2, editText3;
private InputMethodManager imm;
private String mWordSeparators;
private StringBuilder mComposing = new StringBuilder();
private KeyboardView keyboardView;
private Keyboard keyboard;
private Keyboard miKeyboard;
private boolean mCapsLock;
private long mLastShiftTime;
private boolean mCompletionOn;
private long mMetaState;
private CompletionInfo[] mCompletions;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Button button3 = (Button) findViewById(R.id.button3);
button3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
Log.d("cambio estado", "onDestroy");
}
});
Button button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
Log.d("cambio estado", "onDestroy");
}
});
editText1 = (EditText) findViewById(R.id.editText1);
editText2 = (EditText) findViewById(R.id.editText2);
editText3 = (EditText) findViewById(R.id.editText3);
imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText1.getWindowToken(), 0);
imm.hideSoftInputFromWindow(editText2.getWindowToken(), 0);
imm.hideSoftInputFromWindow(editText3.getWindowToken(), 0);
mWordSeparators = getResources().getString(R.string.word_separators);
keyboardView = (KeyboardView) findViewById(R.id.keyboardView);
keyboard = new Keyboard(this, R.xml.qwerty);
miKeyboard = new Keyboard(this,R.xml.qwerty);
keyboardView.setKeyboard(keyboard);
keyboardView.setEnabled(true);
keyboardView.setPreviewEnabled(true);
keyboardView.setOnKeyListener(this);
keyboardView.setOnKeyboardActionListener(this);
}
public void onStartInput(EditorInfo attribute, boolean restarting) {
mComposing.setLength(0);
updateCandidates();
if (!restarting) {
mMetaState = 0;
}
mCompletionOn = false;
mCompletions = null;
switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
case InputType.TYPE_CLASS_NUMBER:
case InputType.TYPE_CLASS_DATETIME:
keyboard = miKeyboard;
break;
case InputType.TYPE_CLASS_PHONE:
keyboard = miKeyboard;
break;
case InputType.TYPE_CLASS_TEXT:
keyboard = miKeyboard;
updateShiftKeyState(attribute);
break;
default:
keyboard = miKeyboard;
updateShiftKeyState(attribute);
}
}
public void onDisplayCompletions(CompletionInfo[] completions) {
if (mCompletionOn) {
if (completions == null) {
return;
}
List<String> stringList = new ArrayList<String>();
for (int i = 0; i < completions.length; i++) {
CompletionInfo ci = completions[i];
if (ci != null) stringList.add(ci.getText().toString());
}
}
}
private boolean translateKeyDown(int keyCode, KeyEvent event) {
mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState,
keyCode, event);
int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState));
mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
InputConnection ic = getCurrentInputConnection();
if (c == 0 || ic == null) {
return false;
}
if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
}
if (mComposing.length() > 0) {
char accent = mComposing.charAt(mComposing.length() -1 );
int composed = KeyEvent.getDeadChar(accent, c);
if (composed != 0) {
c = composed;
mComposing.setLength(mComposing.length()-1);
}
}
onKey(c, null);
return true;
}
private void hideDefaultKeyboard() {
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
private void handleShift() {
checkToggleCapsLock();
keyboardView.setShifted(mCapsLock || !keyboardView.isShifted());
}
private void checkToggleCapsLock() {
long now = System.currentTimeMillis();
if (mLastShiftTime + 800 > now) {
mCapsLock = !mCapsLock;
mLastShiftTime = 0;
} else {
mLastShiftTime = now;
}
}
private void updateCandidates() {
if (!mCompletionOn) {
if (mComposing.length() > 0) {
ArrayList<String> list = new ArrayList<String>();
list.add(mComposing.toString());
}
}
}
private void handleClose() {
commitTyped(getCurrentInputConnection());
keyboardView.closing();
}
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (keyboardView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}
}
public void onText(CharSequence text) {
Log.d(TAG, "onText? \"" + text + "\"");
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
ic.beginBatchEdit();
if (mComposing.length() > 0) {
commitTyped(ic);
}
ic.commitText(text, 0);
ic.endBatchEdit();
updateShiftKeyState((EditorInfo) getCurrentInputEditorInfo());
}
private void updateShiftKeyState(EditorInfo attr) {
if (attr != null
&& keyboardView != null && keyboard == keyboardView.getKeyboard()) {
int caps = 0;
EditorInfo ei = (EditorInfo) getCurrentInputEditorInfo();
if (ei != null && ei.inputType != InputType.TYPE_NULL) {
caps = getCurrentInputConnection().getCursorCapsMode(attr.inputType);
}
keyboardView.setShifted(mCapsLock || caps != 0);
}}
private void commitTyped(InputConnection inputConnection) {
if (mComposing.length() > 0) {
inputConnection.commitText(mComposing, mComposing.length());
mComposing.setLength(0);
updateCandidates();
}
}
private String getWordSeparators() {
return mWordSeparators;
}
public boolean isWordSeparator(int code) {
String separators = getWordSeparators();
return separators.contains(String.valueOf((char)code));
}
private void handleBackspace() {
final int length = mComposing.length();
if (length > 1) {
mComposing.delete(length - 1, length);
getCurrentInputConnection().setComposingText(mComposing, 1);
updateCandidates();
} else if (length > 0) {
mComposing.setLength(0);
getCurrentInputConnection().commitText("", 0);
updateCandidates();
} else {
keyDownUp(KeyEvent.KEYCODE_DEL);
}
updateShiftKeyState(getCurrentInputEditorInfo());
}
private InputConnection getCurrentInputConnection() {
return getCurrentInputConnection();
}
private EditorInfo getCurrentInputEditorInfo() {
return getCurrentInputEditorInfo();
}
#Override
public void swipeUp() {
Log.d(TAG, "swipeUp");
}
#Override
public void swipeRight() {
Log.d(TAG, "swipeRight");
}
#Override
public void swipeLeft() {
Log.d(TAG, "swipeLeft");
handleBackspace();
}
#Override
public void swipeDown() {
Log.d(TAG, "swipeDown");
handleClose();
}
#Override
public void onRelease(int primaryCode) {
Log.d(TAG, "onRelease? primaryCode=" + primaryCode);
}
#Override
public void onPress(int primaryCode) {
Log.d(TAG, "onPress? primaryCode=" + primaryCode);
}
#Override
public void onKey(int primaryCode, int[] keyCodes) {
Log.d(TAG, "onKey? primaryCode=" + primaryCode);
int n1 = 0; // -1 count
for (int keyCode : keyCodes) {
if (keyCode == -1) {
n1++;
continue;
}
Log.v(TAG, "keyCode=" + keyCode);
}
Log.v(TAG, "keyCode=-1 *" + n1);
if (isWordSeparator(primaryCode)) {
if (mComposing.length() > 0) {
commitTyped(getCurrentInputConnection());
}
sendKey(primaryCode);
updateShiftKeyState(getCurrentInputEditorInfo());
} else if (primaryCode == Keyboard.KEYCODE_DELETE) {
handleBackspace();
} else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
handleShift();
} else if (primaryCode == Keyboard.KEYCODE_CANCEL) {
handleClose();
} else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE
&& keyboardView != null) {
Keyboard current = keyboardView.getKeyboard();
keyboardView.setKeyboard(current);
} else {
handleCharacter(primaryCode, keyCodes);
}
}
private void sendKey(int keyCode) {
switch (keyCode) {
case '\n':
keyDownUp(KeyEvent.KEYCODE_ENTER);
break;
default:
if (keyCode >= '0' && keyCode <= '9') {
keyDownUp(keyCode - '0' + KeyEvent.KEYCODE_0);
} else {
getCurrentInputConnection().commitText(String.valueOf((char) keyCode), 1);
}
break;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (event.getRepeatCount() == 0 && keyboardView != null) {
if (keyboardView.handleBack()) {
return true;
}
}
break;
case KeyEvent.KEYCODE_DEL:
if (mComposing.length() > 0) {
onKey(Keyboard.KEYCODE_DELETE, null);
return true;
}
break;
case KeyEvent.KEYCODE_ENTER:
return false;
default:
if (mCapsLock) {
if (keyCode == KeyEvent.KEYCODE_SPACE
&& (event.getMetaState()&KeyEvent.META_ALT_ON) != 0) {
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.clearMetaKeyStates(KeyEvent.META_ALT_ON);
keyDownUp(KeyEvent.KEYCODE_A);
keyDownUp(KeyEvent.KEYCODE_N);
keyDownUp(KeyEvent.KEYCODE_D);
keyDownUp(KeyEvent.KEYCODE_R);
keyDownUp(KeyEvent.KEYCODE_O);
keyDownUp(KeyEvent.KEYCODE_I);
keyDownUp(KeyEvent.KEYCODE_D);
return true;
}
}
if (translateKeyDown(keyCode, event)) {
return true;
}
}
}
return super.onKeyDown(keyCode, event);
}
private void keyDownUp(int keyEventCode) {
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode));
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_UP, keyEventCode));
}
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
hideDefaultKeyboard();
Log.d(TAG, "onKey? keyCode=" + keyCode);
return false;
}
}
In your Xml file, Inside the editText tag you find something like android:inputType attribute. you can specify different types of input types like textEmail, phoneNumber, textPassword.
There are so many types, if you specify the input type attribute, it will show custom keyboard according to input type,
If your editText input type is a phoneNumber, then it will show Num KeyPad
If your editText input type is a textPassword, then it will show Character Keypad
Like this, you can have more custom keypad / keyboard
For Password keypad,
<EditText android:id=..........
android:inputType="textPassword" />
For Numeric Keypad
<EditText android:id=..........
android:inputType="number" />
have you declared it in manifest like
<service
android:name="TamilSoftKeyboard"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data
android:name="android.view.im"
android:resource="#xml/method" />
</service>