List of usage examples for android.view.inputmethod InputMethodManager showSoftInput
public boolean showSoftInput(View view, int flags)
From source file:foam.mongoose.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { try {/*from ww w .jav a2 s . c o m*/ String type = arr.getString(0); final Integer id = arr.getInt(1); String token = arr.getString(2); //Log.i("starwisp", "Update: "+type+" "+id+" "+token); // non widget commands if (token.equals("toast")) { Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT); msg.show(); return; } if (token.equals("play-sound")) { String name = arr.getString(3); if (name.equals("ping")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping); mp.start(); } if (name.equals("active")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active); mp.start(); } } if (token.equals("vibrate")) { Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(arr.getInt(3)); } if (type.equals("replace-fragment")) { int ID = arr.getInt(1); String name = arr.getString(2); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); //ft.setCustomAnimations( // R.animator.card_flip_right_in, R.animator.card_flip_right_out, // R.animator.card_flip_left_in, R.animator.card_flip_left_out); ft.replace(ID, fragment); //ft.addToBackStack(null); ft.commit(); return; } if (token.equals("dialog-fragment")) { FragmentManager fm = ctx.getSupportFragmentManager(); final int ID = arr.getInt(3); final JSONArray lp = arr.getJSONArray(4); final String name = arr.getString(5); final Dialog dialog = new Dialog(ctx); dialog.setTitle("Title..."); LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); dialog.setContentView(inner); // Fragment fragment = ActivityManager.GetFragment(name); // FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); // fragmentTransaction.add(ID,fragment); // fragmentTransaction.commit(); dialog.show(); /* DialogFragment df = new DialogFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); return inner; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog ret = super.onCreateDialog(savedInstanceState); Log.i("starwisp","MAKINGDAMNFRAGMENT"); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(1,fragment); fragmentTransaction.commit(); return ret; } }; df.show(ctx.getFragmentManager(), "foo"); */ } if (token.equals("time-picker-dialog")) { final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); // Create a new instance of TimePickerDialog and return it TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true); d.show(); return; } ; if (token.equals("make-directory")) { File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3)); file.mkdirs(); return; } if (token.equals("list-files")) { final String name = arr.getString(3); File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5)); // todo, should probably call callback with empty list if (file != null) { File list[] = file.listFiles(); if (list != null) { String code = "("; for (int i = 0; i < list.length; i++) { code += " \"" + list[i].getName() + "\""; } code += ")"; DialogCallback(ctx, ctxname, name, code); } } return; } if (token.equals("gps-start")) { final String name = arr.getString(3); if (m_LocationManager == null) { m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); m_GPS = new DorisLocationListener(m_LocationManager); } m_GPS.Start((StarwispActivity) ctx, name, this); return; } if (token.equals("delayed")) { final String name = arr.getString(3); final int d = arr.getInt(5); Runnable timerThread = new Runnable() { public void run() { DialogCallback(ctx, ctxname, name, ""); } }; m_Handler.removeCallbacksAndMessages(null); m_Handler.postDelayed(timerThread, d); return; } if (token.equals("network-connect")) { final String name = arr.getString(3); final String ssid = arr.getString(5); m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this); return; } if (token.equals("http-request")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http request"); final String name = arr.getString(3); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "normal", name); } return; } if (token.equals("http-download")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http dl request"); final String filename = arr.getString(4); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "download", filename); } return; } if (token.equals("send-mail")) { final String to[] = new String[1]; to[0] = arr.getString(3); final String subject = arr.getString(4); final String body = arr.getString(5); JSONArray attach = arr.getJSONArray(6); ArrayList<String> paths = new ArrayList<String>(); for (int a = 0; a < attach.length(); a++) { Log.i("starwisp", attach.getString(a)); paths.add(attach.getString(a)); } email(ctx, to[0], "", subject, body, paths); } if (token.equals("date-picker-dialog")) { final Calendar c = Calendar.getInstance(); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH); int year = c.get(Calendar.YEAR); final String name = arr.getString(3); // Create a new instance of TimePickerDialog and return it DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int month, int day) { DialogCallback(ctx, ctxname, name, day + " " + month + " " + year); } }, year, month, day); d.show(); return; } ; if (token.equals("alert-dialog")) { final String name = arr.getString(3); final String msg = arr.getString(5); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int result = 0; if (which == DialogInterface.BUTTON_POSITIVE) result = 1; DialogCallback(ctx, ctxname, name, "" + result); } }; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return; } if (token.equals("start-activity")) { ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5)); return; } if (token.equals("start-activity-goto")) { ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4)); return; } if (token.equals("finish-activity")) { ctx.setResult(arr.getInt(3)); ctx.finish(); return; } /////////////////////////////////////////////////////////// // problem associating the id number if (id == 0) return; // now try and find the widget View vv = ctx.findViewById(id); if (vv == null) { Log.i("starwisp", "Can't find widget : " + id); return; } // tokens that work on everything if (token.equals("hide")) { vv.setVisibility(View.GONE); return; } if (token.equals("show")) { vv.setVisibility(View.VISIBLE); return; } // tokens that work on everything if (token.equals("set-enabled")) { vv.setEnabled(arr.getInt(3) == 1); return; } // special cases if (type.equals("linear-layout")) { LinearLayout v = (LinearLayout) vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } } } if (type.equals("button-grid")) { LinearLayout horiz = (LinearLayout) vv; if (token.equals("grid-buttons")) { horiz.removeAllViews(); JSONArray params = arr.getJSONArray(3); String buttontype = params.getString(0); int height = params.getInt(1); int textsize = params.getInt(2); LinearLayout.LayoutParams lp = BuildLayoutParams(params.getJSONArray(3)); final JSONArray buttons = params.getJSONArray(4); final int count = buttons.length(); int vertcount = 0; LinearLayout vert = null; for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); if (vertcount == 0) { vert = new LinearLayout(ctx); vert.setId(0); vert.setOrientation(LinearLayout.VERTICAL); horiz.addView(vert); } vertcount = (vertcount + 1) % height; if (buttontype.equals("button")) { Button b = new Button(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } else if (buttontype.equals("toggle")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg); } }); vert.addView(b); } else if (buttontype.equals("single")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); int bid = button.getInt(0); if (bid != v.getId()) { ToggleButton tb = (ToggleButton) ctx.findViewById(bid); tb.setChecked(false); } } } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } } } } /* if (type.equals("grid-layout")) { GridLayout v = (GridLayout)vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } } } */ if (type.equals("view-pager")) { ViewPager v = (ViewPager) vv; if (token.equals("switch")) { v.setCurrentItem(arr.getInt(3)); } if (token.equals("pages")) { final JSONArray items = arr.getJSONArray(3); v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) { @Override public int getCount() { return items.length(); } @Override public Fragment getItem(int position) { try { String fragname = items.getString(position); return ActivityManager.GetFragment(fragname); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } return null; } }); } } if (type.equals("image-view")) { ImageView v = (ImageView) vv; if (token.equals("image")) { int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName()); v.setImageResource(iid); } if (token.equals("external-image")) { Bitmap bitmap = BitmapFactory.decodeFile(arr.getString(3)); v.setImageBitmap(bitmap); } return; } if (type.equals("text-view") || type.equals("debug-text-view")) { TextView v = (TextView) vv; if (token.equals("text")) { if (type.equals("debug-text-view")) { //v.setMovementMethod(new ScrollingMovementMethod()); } v.setText(arr.getString(3)); } return; } if (type.equals("edit-text")) { EditText v = (EditText) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("request-focus")) { v.requestFocus(); InputMethodManager imm = (InputMethodManager) ctx .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); } return; } if (type.equals("button")) { Button v = (Button) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("toggle-button")) { ToggleButton v = (ToggleButton) vv; if (token.equals("text")) { v.setText(arr.getString(3)); return; } if (token.equals("checked")) { if (arr.getInt(3) == 0) v.setChecked(false); else v.setChecked(true); return; } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("canvas")) { StarwispCanvas v = (StarwispCanvas) vv; if (token.equals("drawlist")) { v.SetDrawList(arr.getJSONArray(3)); } return; } if (type.equals("camera-preview")) { final CameraPreview v = (CameraPreview) vv; if (token.equals("take-picture")) { final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3); v.TakePicture(new PictureCallback() { public void onPictureTaken(byte[] data, Camera camera) { String datetime = getDateTime(); String filename = path + datetime + ".jpg"; SaveData(filename, data); v.Shutdown(); ctx.finish(); } }); } if (token.equals("shutdown")) { v.Shutdown(); } return; } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); if (token.equals("max")) { // android seekbar bug workaround int p = v.getProgress(); v.setMax(0); v.setProgress(0); v.setMax(arr.getInt(3)); v.setProgress(1000); // not working.... :( } } if (type.equals("spinner")) { Spinner v = (Spinner) vv; if (token.equals("selection")) { v.setSelection(arr.getInt(3)); } if (token.equals("array")) { final JSONArray items = arr.getJSONArray(3); ArrayList<String> spinnerArray = new ArrayList<String>(); for (int i = 0; i < items.length(); i++) { spinnerArray.add(items.getString(i)); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, android.R.layout.simple_spinner_item, spinnerArray) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface); return v; } }; v.setAdapter(spinnerArrayAdapter); final int wid = id; // need to update for new values v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { try { CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\""); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } } public void onNothingSelected(AdapterView<?> v) { } }); } return; } } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } }
From source file:dev.ukanth.ufirewall.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { /*case android.R.id.home: disableOrEnable();//from w ww. j ava 2s . c om return true;*/ case R.id.menu_toggle: disableOrEnable(); return true; case R.id.menu_apply: applyOrSaveRules(); return true; case R.id.menu_exit: finish(); System.exit(0); return false; case R.id.menu_help: showAbout(); return true; /*case R.id.menu_setpwd: setPassword(); return true;*/ case R.id.menu_log: showLog(); return true; case R.id.menu_rules: showRules(); return true; case R.id.menu_setcustom: setCustomScript(); return true; case R.id.menu_preference: showPreferences(); return true; /*case R.id.menu_reload: Api.applications = null; showOrLoadApplications(); return true;*/ case R.id.menu_search: item.setActionView(R.layout.searchbar); final EditText filterText = (EditText) item.getActionView().findViewById(R.id.searchApps); filterText.addTextChangedListener(filterTextWatcher); filterText.setEllipsize(TruncateAt.END); filterText.setSingleLine(); MenuItemCompat.setOnActionExpandListener(item, new MenuItemCompat.OnActionExpandListener() { @Override public boolean onMenuItemActionCollapse(MenuItem item) { // Do something when collapsed return true; // Return true to collapse action view } @Override public boolean onMenuItemActionExpand(MenuItem item) { filterText.post(new Runnable() { @Override public void run() { filterText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.showSoftInput(filterText, InputMethodManager.SHOW_IMPLICIT); } }); return true; // Return true to expand action view } }); return true; case R.id.menu_export: new MaterialDialog.Builder(this).title(R.string.exports).cancelable(false) .items(new String[] { getString(R.string.export_rules), getString(R.string.export_all) }) .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { switch (which) { case 0: Api.saveSharedPreferencesToFileConfirm(MainActivity.this); break; case 1: Api.saveAllPreferencesToFileConfirm(MainActivity.this); break; } return true; } }).positiveText(R.string.exports).negativeText(R.string.Cancel).show(); return true; case R.id.menu_import: new MaterialDialog.Builder(this).title(R.string.imports).cancelable(false) .items(new String[] { getString(R.string.import_rules), getString(R.string.import_all), getString(R.string.import_rules_droidwall) }) .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { switch (which) { case 0: //Intent intent = new Intent(MainActivity.this, FileChooserActivity.class); //startActivityForResult(intent, FILE_CHOOSER_LOCAL); File mPath = new File(Environment.getExternalStorageDirectory() + "//afwall//"); FileDialog fileDialog = new FileDialog(MainActivity.this, mPath, true); //fileDialog.setFlag(true); //fileDialog.setFileEndsWith(new String[] {"backup", "afwall-backup"}, "all"); fileDialog.addFileListener(new FileDialog.FileSelectedListener() { public void fileSelected(File file) { String fileSelected = file.toString(); StringBuilder builder = new StringBuilder(); if (Api.loadSharedPreferencesFromFile(MainActivity.this, builder, fileSelected)) { Api.applications = null; showOrLoadApplications(); Api.toast(MainActivity.this, getString(R.string.import_rules_success) + fileSelected); } else { if (builder.toString().equals("")) { Api.toast(MainActivity.this, getString(R.string.import_rules_fail)); } else { Api.toast(MainActivity.this, builder.toString()); } } } }); fileDialog.showDialog(); break; case 1: if (Api.getCurrentPackage(MainActivity.this).equals("dev.ukanth.ufirewall.donate") || G.isDo(getApplicationContext())) { File mPath2 = new File( Environment.getExternalStorageDirectory() + "//afwall//"); FileDialog fileDialog2 = new FileDialog(MainActivity.this, mPath2, false); //fileDialog2.setFlag(false); //fileDialog2.setFileEndsWith(new String[] {"backup_all", "afwall-backup-all"}, "" ); fileDialog2.addFileListener(new FileDialog.FileSelectedListener() { public void fileSelected(File file) { String fileSelected = file.toString(); StringBuilder builder = new StringBuilder(); if (Api.loadAllPreferencesFromFile(MainActivity.this, builder, fileSelected)) { Api.applications = null; showOrLoadApplications(); Api.toast(MainActivity.this, getString(R.string.import_rules_success) + fileSelected); Intent intent = getIntent(); finish(); startActivity(intent); } else { if (builder.toString().equals("")) { Api.toast(MainActivity.this, getString(R.string.import_rules_fail)); } else { Api.toast(MainActivity.this, builder.toString()); } } } }); fileDialog2.showDialog(); } else { new MaterialDialog.Builder(MainActivity.this).cancelable(false) .title(R.string.buy_donate).content(R.string.donate_only) .positiveText(R.string.buy_donate).negativeText(R.string.close) .icon(getResources().getDrawable(R.drawable.ic_launcher)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://search?q=pub:ukpriya")); startActivity(intent); } @Override public void onNegative(MaterialDialog dialog) { dialog.cancel(); } }).show(); } break; case 2: new MaterialDialog.Builder(MainActivity.this).cancelable(false) .title(R.string.import_rules_droidwall).content(R.string.overrideRules) .positiveText(R.string.Yes).negativeText(R.string.No) .icon(getResources().getDrawable(R.drawable.ic_launcher)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { if (ImportApi .loadSharedPreferencesFromDroidWall(MainActivity.this)) { Api.applications = null; showOrLoadApplications(); Api.toast(MainActivity.this, getString(R.string.import_rules_success) + Environment .getExternalStorageDirectory().getAbsolutePath() + "/afwall/"); } else { Api.toast(MainActivity.this, getString(R.string.import_rules_fail)); } } @Override public void onNegative(MaterialDialog dialog) { dialog.cancel(); } }).show(); break; } return true; } }).positiveText(R.string.imports).negativeText(R.string.Cancel).show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.wewow.MainActivity.java
private void showCover() { toolbar.setBackgroundColor(getResources().getColor(R.color.cover)); if (isAppBarFolded) { imageViewLine.setBackgroundColor(getResources().getColor(R.color.cover)); mTabLayout.setBackgroundColor(getResources().getColor(R.color.cover)); layoutCoverTab.setVisibility(View.VISIBLE); layoutCoverTab.setOnClickListener(new View.OnClickListener() { @Override/* ww w . j a va 2 s.co m*/ public void onClick(View v) { removeCover(true); } }); } RelativeLayout layoutCover = (RelativeLayout) findViewById(R.id.layoutCover); layoutCover.setVisibility(View.VISIBLE); layoutCover.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // searchView.setVisibility(View.INVISIBLE); // if(isAppBarFolded) // { // textTitle.setVisibility(View.VISIBLE); // } removeCover(true); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.setVisibility(View.INVISIBLE); imageViewUnderLine.setVisibility(View.INVISIBLE); RemoveUnderLine(); searchView.setText(""); resetDropdownOffset = true; imageViewHome.setImageResource(R.drawable.menu); isSearchViewShown = false; if (isAppBarFolded) { textTitle.setVisibility(View.VISIBLE); imageViewHome.setImageResource(R.drawable.menu_b); } } }, 200); } }); ImageView imageViewBack = (ImageView) findViewById(R.id.layoutMenuCover); imageViewBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isSearchViewShown) { drawerLayout.openDrawer(GravityCompat.START); } else { removeCover(true); new Handler().postDelayed(new Runnable() { public void run() { //execute the task if (isAppBarFolded) { textTitle.setVisibility(View.VISIBLE); imageViewHome.setImageResource(R.drawable.menu_b); imageViewUnderLine.setVisibility(View.INVISIBLE); } searchView.setVisibility(View.INVISIBLE); imageViewUnderLine.setVisibility(View.INVISIBLE); RemoveUnderLine(); searchView.setText(""); resetDropdownOffset = true; imageViewHome.setImageResource(R.drawable.menu); isSearchViewShown = false; } }, 200); } } }); ImageView imageViewSearchBottom = (ImageView) findViewById(R.id.layoutSearchCover); imageViewSearchBottom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String queryText = searchView.getText().toString().trim(); if (!isSearchViewShown) { if (isAppBarFolded) { imageViewHome.setImageResource(R.drawable.back_b); } else { imageViewHome.setImageResource(R.drawable.back); } ListSearchAdapter adapter = new ListSearchAdapter(hotWords, MainActivity.this); // // ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, R.layout.list_item_search, R.id.text, hotWords); searchView.setAdapter(adapter); searchView.setHint(getResources().getString(R.string.search_hint)); searchView.setThreshold(0); if (resetDropdownOffset) { // searchView.setDropDownVerticalOffset(40); // resetDropdownOffset = false; } showUnderLine(); showCover(); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.setVisibility(View.VISIBLE); textTitle.setVisibility(View.GONE); searchView.requestFocus(); InputMethodManager inputManager = (InputMethodManager) searchView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(searchView, 0); } }, 100); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.showDropDown(); } }, 200); searchView.addTextChangedListener(MainActivity.this); searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { searchView.setText(hotWords.get(position), true); removeCover(true); layoutSearch.performClick(); } else { searchView.setText(""); } // } }); searchView.setThreshold(0); isSearchViewShown = true; } else { if (!queryText.equals("")) { searchView.setText(""); searchView.setVisibility(View.INVISIBLE); imageViewUnderLine.setVisibility(View.INVISIBLE); Intent intentSearch = new Intent(MainActivity.this, SearchResultActivity.class); intentSearch.putExtra("key_word", queryText); startActivity(intentSearch); if (isAppBarFolded) { imageViewHome.setImageResource(R.drawable.menu_b); } else { imageViewHome.setImageResource(R.drawable.menu); } isSearchViewShown = false; if (isAppBarFolded) { textTitle.setVisibility(View.VISIBLE); } } else { if (isAppBarFolded) { imageViewHome.setImageResource(R.drawable.back_b); } else { imageViewHome.setImageResource(R.drawable.back); } searchView.setHint(getResources().getString(R.string.search_hint)); final String[] testStrings = getResources().getStringArray(R.array.test_array); // ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, R.layout.list_item_search, R.id.text, hotWords); ListSearchAdapter adapter = new ListSearchAdapter(hotWords, MainActivity.this); searchView.setAdapter(adapter); searchView.requestFocus(); if (resetDropdownOffset) { // resetDropdownOffset = false; // searchView.setDropDownVerticalOffset(-40); } // searchView.setDropDownVerticalOffset(-40); showUnderLine(); showCover(); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.setVisibility(View.VISIBLE); textTitle.setVisibility(View.GONE); searchView.requestFocus(); InputMethodManager inputManager = (InputMethodManager) searchView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(searchView, 0); } }, 100); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.showDropDown(); } }, 200); searchView.addTextChangedListener(MainActivity.this); searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { searchView.setText(hotWords.get(position), true); removeCover(true); imageViewSearch.performClick(); } // } }); searchView.setThreshold(0); isSearchViewShown = true; } } } }); }
From source file:com.wewow.MainActivity.java
private void initAppBar() { imageViewHome = (ImageView) findViewById(R.id.btnBack); imageViewSearch = (ImageView) findViewById(R.id.btnSearch); textTitle = (TextView) findViewById(R.id.textTitle); imageViewUnderLine = (ImageView) findViewById(R.id.imageViewUnderlineOfSearchView); searchView = (AutoCompleteTextView) findViewById(R.id.editTextSearch); layoutMenu = (ImageView) findViewById(R.id.layoutMenu); layoutSearch = (ImageView) findViewById(R.id.layoutSearch); layoutMenu.setOnClickListener(new View.OnClickListener() { @Override//w w w. j a v a2s . co m public void onClick(View v) { if (!isSearchViewShown) { drawerLayout.openDrawer(GravityCompat.START); } else { removeCover(true); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.setVisibility(View.INVISIBLE); imageViewUnderLine.setVisibility(View.INVISIBLE); RemoveUnderLine(); searchView.setText(""); resetDropdownOffset = true; imageViewHome.setImageResource(R.drawable.menu); isSearchViewShown = false; if (isAppBarFolded) { textTitle.setVisibility(View.VISIBLE); imageViewHome.setImageResource(R.drawable.menu_b); } } }, 200); } } }); mTabLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { removeCover(true); } }); layoutSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String queryText = searchView.getText().toString().trim(); if (!isSearchViewShown) { if (isAppBarFolded) { imageViewHome.setImageResource(R.drawable.back_b); } else { imageViewHome.setImageResource(R.drawable.back); } ListSearchAdapter adapter = new ListSearchAdapter(hotWords, MainActivity.this); // // ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, R.layout.list_item_search, R.id.text, hotWords); searchView.setAdapter(adapter); searchView.setHint(getResources().getString(R.string.search_hint)); searchView.setThreshold(0); if (resetDropdownOffset) { // searchView.setDropDownVerticalOffset(40); // resetDropdownOffset = false; } showUnderLine(); showCover(); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.setVisibility(View.VISIBLE); textTitle.setVisibility(View.GONE); searchView.requestFocus(); InputMethodManager inputManager = (InputMethodManager) searchView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(searchView, 0); } }, 100); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.showDropDown(); } }, 200); searchView.addTextChangedListener(MainActivity.this); searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { searchView.setText(hotWords.get(position), true); removeCover(true); layoutSearch.performClick(); } else { searchView.setText(""); } // } }); searchView.setThreshold(0); isSearchViewShown = true; } else { if (!queryText.equals("")) { searchView.setText(""); searchView.setVisibility(View.INVISIBLE); imageViewUnderLine.setVisibility(View.INVISIBLE); Intent intentSearch = new Intent(MainActivity.this, SearchResultActivity.class); intentSearch.putExtra("key_word", queryText); startActivity(intentSearch); if (isAppBarFolded) { imageViewHome.setImageResource(R.drawable.menu_b); } else { imageViewHome.setImageResource(R.drawable.menu); } isSearchViewShown = false; if (isAppBarFolded) { textTitle.setVisibility(View.VISIBLE); } } else { if (isAppBarFolded) { imageViewHome.setImageResource(R.drawable.back_b); } else { imageViewHome.setImageResource(R.drawable.back); } searchView.setHint(getResources().getString(R.string.search_hint)); final String[] testStrings = getResources().getStringArray(R.array.test_array); // ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, R.layout.list_item_search, R.id.text, hotWords); ListSearchAdapter adapter = new ListSearchAdapter(hotWords, MainActivity.this); searchView.setAdapter(adapter); searchView.requestFocus(); if (resetDropdownOffset) { // resetDropdownOffset = false; // searchView.setDropDownVerticalOffset(-40); } // searchView.setDropDownVerticalOffset(-40); showUnderLine(); showCover(); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.setVisibility(View.VISIBLE); textTitle.setVisibility(View.GONE); searchView.requestFocus(); InputMethodManager inputManager = (InputMethodManager) searchView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(searchView, 0); } }, 100); new Handler().postDelayed(new Runnable() { public void run() { //execute the task searchView.showDropDown(); } }, 200); searchView.addTextChangedListener(MainActivity.this); searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { searchView.setText(hotWords.get(position), true); removeCover(true); imageViewSearch.performClick(); } // } }); searchView.setThreshold(0); isSearchViewShown = true; } } } }); mAppBarLayout = (AppBarLayout) findViewById(R.id.appbar); if (Build.VERSION.SDK_INT >= 21) { mAppBarLayout.setNestedScrollingEnabled(false); } mAppBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override public void onStateChanged(AppBarLayout appBarLayout, State state) { Log.d("STATE", state.name()); if (state == State.EXPANDED) { searchView.setTextColor(getResources().getColor(R.color.search_text_view_color)); searchView.setHintTextColor(getResources().getColor(R.color.search_text_view_hint_color)); imageViewHome.setImageResource(R.drawable.menu); imageViewSearch.setImageResource(R.drawable.search); textTitle.setVisibility(View.GONE); searchView.setVisibility(View.INVISIBLE); imageViewUnderLine.setVisibility(View.INVISIBLE); imageViewUnderLine.setImageResource(R.color.white); isAppBarFolded = false; toolbar.setBackgroundColor(getResources().getColor(R.color.transparent)); //? } else if (state == State.COLLAPSED) { searchView.setTextColor(getResources().getColor(R.color.font_color)); searchView.setHintTextColor(getResources().getColor(R.color.search_hot_search)); imageViewHome.setImageResource(R.drawable.menu_b); imageViewSearch.setImageResource(R.drawable.search_b); textTitle.setVisibility(View.VISIBLE); resetDropdownOffset = true; searchView.setVisibility(View.INVISIBLE); imageViewUnderLine.clearAnimation(); imageViewUnderLine.setVisibility(View.INVISIBLE); imageViewUnderLine.setImageResource(R.color.search_hot_search); toolbar.setBackgroundColor(getResources().getColor(R.color.white)); isAppBarFolded = true; //?? } else { toolbar.setBackgroundColor(getResources().getColor(R.color.transparent)); //? } } }); }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private void animateRevealShow(View targetview, View startView) { if (isActionInsertOrEdit()) { final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); int cx = startView.getLeft() + (startView.getWidth() / 2); //middle of button int cy = startView.getTop() + (startView.getHeight() / 2); //middle of button int radius = (int) Math.sqrt(Math.pow(cx, 2) + Math.pow(cy, 2)); //hypotenuse to top left Animator anim = ViewAnimationUtils.createCircularReveal(targetview, cx, cy, 0, radius); targetview.setVisibility(View.VISIBLE); anim.setInterpolator(new DecelerateInterpolator()); anim.addListener(new Animator.AnimatorListener() { @Override/* w w w. ja v a 2 s. co m*/ public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mNoteEditor.requestFocus(); imm.showSoftInput(mNoteEditor, 0); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); anim.setDuration(ANIM_DURATION); anim.start(); } else if (isActionActionView()) { mAnimBackGroudView.animate().scaleX(.92f).scaleY(.92f).alpha(.6f).setDuration(ANIM_DURATION) .setInterpolator(new AccelerateInterpolator()).start(); mNoteEditor.animate().alpha(1).setStartDelay(400).setDuration(ANIM_DURATION); ViewCompat.setTransitionName(mAnimTargetView, "target_anim_view"); } }
From source file:com.vuze.android.remote.fragment.TorrentListFragment.java
private boolean handleFragmentMenuItems(int itemId) { if (AndroidUtils.DEBUG_MENU) { Log.d(TAG, "HANDLE MENU FRAG " + itemId); }// www.j av a 2 s .c o m if (sessionInfo == null) { return false; } if (itemId == R.id.action_filterby) { DialogFragmentFilterBy.openFilterByDialog(this, sessionInfo, sessionInfo.getRemoteProfile().getID()); return true; } else if (itemId == R.id.action_filter) { boolean newVisibility = filterEditText.getVisibility() != View.VISIBLE; filterEditText.setVisibility(newVisibility ? View.VISIBLE : View.GONE); if (newVisibility) { filterEditText.requestFocus(); InputMethodManager mgr = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(filterEditText, InputMethodManager.SHOW_IMPLICIT); VuzeEasyTracker.getInstance(this).sendEvent("uiAction", "ViewShown", "FilterBox", null); } else { InputMethodManager mgr = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(filterEditText.getWindowToken(), 0); } return true; } else if (itemId == R.id.action_sortby) { DialogFragmentSortBy.open(getFragmentManager(), this); return true; } return handleTorrentMenuActions(sessionInfo, getCheckedIDs(torrentListAdapter, true), getFragmentManager(), itemId); }
From source file:foam.opensauces.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { try {//from ww w . j a va2s . co m String type = arr.getString(0); final Integer id = arr.getInt(1); String token = arr.getString(2); Log.i("starwisp", "Update: " + type + " " + id + " " + token); // non widget commands if (token.equals("toast")) { Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT); msg.show(); return; } if (token.equals("play-sound")) { String name = arr.getString(3); if (name.equals("ping")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping); mp.start(); } if (name.equals("active")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active); mp.start(); } } if (token.equals("vibrate")) { Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(arr.getInt(3)); } if (type.equals("replace-fragment")) { int ID = arr.getInt(1); String name = arr.getString(2); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); //ft.setCustomAnimations( // R.animator.card_flip_right_in, R.animator.card_flip_right_out, // R.animator.card_flip_left_in, R.animator.card_flip_left_out); ft.replace(ID, fragment); //ft.addToBackStack(null); ft.commit(); return; } if (token.equals("dialog-fragment")) { FragmentManager fm = ctx.getSupportFragmentManager(); final int ID = arr.getInt(3); final JSONArray lp = arr.getJSONArray(4); final String name = arr.getString(5); final Dialog dialog = new Dialog(ctx); dialog.setTitle("Title..."); LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); dialog.setContentView(inner); // Fragment fragment = ActivityManager.GetFragment(name); // FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); // fragmentTransaction.add(ID,fragment); // fragmentTransaction.commit(); dialog.show(); /* DialogFragment df = new DialogFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout inner = new LinearLayout(ctx); inner.setId(ID); inner.setLayoutParams(BuildLayoutParams(lp)); return inner; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog ret = super.onCreateDialog(savedInstanceState); Log.i("starwisp","MAKINGDAMNFRAGMENT"); Fragment fragment = ActivityManager.GetFragment(name); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(1,fragment); fragmentTransaction.commit(); return ret; } }; df.show(ctx.getFragmentManager(), "foo"); */ } if (token.equals("time-picker-dialog")) { final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); // Create a new instance of TimePickerDialog and return it TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true); d.show(); return; } ; if (token.equals("make-directory")) { File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3)); file.mkdirs(); return; } if (token.equals("list-files")) { final String name = arr.getString(3); File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5)); // todo, should probably call callback with empty list if (file != null) { File list[] = file.listFiles(); if (list != null) { String code = "("; for (int i = 0; i < list.length; i++) { code += " \"" + list[i].getName() + "\""; } code += ")"; DialogCallback(ctx, ctxname, name, code); } } return; } if (token.equals("gps-start")) { final String name = arr.getString(3); if (m_LocationManager == null) { m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); m_GPS = new DorisLocationListener(m_LocationManager); } m_GPS.Start((StarwispActivity) ctx, name, this); return; } if (token.equals("walk-draggable")) { final String name = arr.getString(3); int iid = arr.getInt(5); DialogCallback(ctx, ctxname, name, WalkDraggable(ctx, name, ctxname, iid)); return; } if (token.equals("delayed")) { final String name = arr.getString(3); final int d = arr.getInt(5); Runnable timerThread = new Runnable() { public void run() { DialogCallback(ctx, ctxname, name, ""); } }; m_Handler.removeCallbacksAndMessages(null); m_Handler.postDelayed(timerThread, d); return; } if (token.equals("network-connect")) { final String name = arr.getString(3); final String ssid = arr.getString(5); m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this); return; } if (token.equals("http-request")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http request"); final String name = arr.getString(3); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "normal", name); } return; } if (token.equals("http-download")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http dl request"); final String filename = arr.getString(4); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "download", filename); } return; } if (token.equals("send-mail")) { final String to[] = new String[1]; to[0] = arr.getString(3); final String subject = arr.getString(4); final String body = arr.getString(5); JSONArray attach = arr.getJSONArray(6); ArrayList<String> paths = new ArrayList<String>(); for (int a = 0; a < attach.length(); a++) { Log.i("starwisp", attach.getString(a)); paths.add(attach.getString(a)); } email(ctx, to[0], "", subject, body, paths); } if (token.equals("date-picker-dialog")) { final Calendar c = Calendar.getInstance(); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH); int year = c.get(Calendar.YEAR); final String name = arr.getString(3); // Create a new instance of TimePickerDialog and return it DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int month, int day) { DialogCallback(ctx, ctxname, name, day + " " + month + " " + year); } }, year, month, day); d.show(); return; } ; if (token.equals("alert-dialog")) { final String name = arr.getString(3); final String msg = arr.getString(5); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int result = 0; if (which == DialogInterface.BUTTON_POSITIVE) result = 1; DialogCallback(ctx, ctxname, name, "" + result); } }; AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); return; } if (token.equals("start-activity")) { ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5)); return; } if (token.equals("start-activity-goto")) { ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4)); return; } if (token.equals("finish-activity")) { ctx.setResult(arr.getInt(3)); ctx.finish(); return; } /////////////////////////////////////////////////////////// // now try and find the widget View vv = ctx.findViewById(id); if (vv == null) { Log.i("starwisp", "Can't find widget : " + id); return; } // tokens that work on everything if (token.equals("hide")) { vv.setVisibility(View.GONE); return; } if (token.equals("show")) { vv.setVisibility(View.VISIBLE); return; } // tokens that work on everything if (token.equals("set-enabled")) { vv.setEnabled(arr.getInt(3) == 1); return; } // special cases if (type.equals("linear-layout")) { LinearLayout v = (LinearLayout) vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } } } // special cases if (type.equals("draggable")) { LinearLayout v = (LinearLayout) vv; if (token.equals("contents")) { // v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } } } if (type.equals("button-grid")) { LinearLayout horiz = (LinearLayout) vv; if (token.equals("grid-buttons")) { horiz.removeAllViews(); JSONArray params = arr.getJSONArray(3); String buttontype = params.getString(0); int height = params.getInt(1); int textsize = params.getInt(2); LinearLayout.LayoutParams lp = BuildLayoutParams(params.getJSONArray(3)); final JSONArray buttons = params.getJSONArray(4); final int count = buttons.length(); int vertcount = 0; LinearLayout vert = null; for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); if (vertcount == 0) { vert = new LinearLayout(ctx); vert.setId(0); vert.setOrientation(LinearLayout.VERTICAL); horiz.addView(vert); } vertcount = (vertcount + 1) % height; if (buttontype.equals("button")) { Button b = new Button(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } else if (buttontype.equals("toggle")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg); } }); vert.addView(b); } else if (buttontype.equals("single")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = params.getString(5); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); int bid = button.getInt(0); if (bid != v.getId()) { ToggleButton tb = (ToggleButton) ctx.findViewById(bid); tb.setChecked(false); } } } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } } } } /* if (type.equals("grid-layout")) { GridLayout v = (GridLayout)vv; if (token.equals("contents")) { v.removeAllViews(); JSONArray children = arr.getJSONArray(3); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } } } */ if (type.equals("view-pager")) { ViewPager v = (ViewPager) vv; if (token.equals("switch")) { v.setCurrentItem(arr.getInt(3)); } if (token.equals("pages")) { final JSONArray items = arr.getJSONArray(3); v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) { @Override public int getCount() { return items.length(); } @Override public Fragment getItem(int position) { try { String fragname = items.getString(position); return ActivityManager.GetFragment(fragname); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } return null; } }); } } if (type.equals("image-view")) { ImageView v = (ImageView) vv; if (token.equals("image")) { int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName()); v.setImageResource(iid); } if (token.equals("external-image")) { Bitmap bitmap = BitmapFactory.decodeFile(arr.getString(3)); v.setImageBitmap(bitmap); } return; } if (type.equals("text-view") || type.equals("debug-text-view")) { TextView v = (TextView) vv; if (token.equals("text")) { if (type.equals("debug-text-view")) { //v.setMovementMethod(new ScrollingMovementMethod()); } v.setText(arr.getString(3)); } return; } if (type.equals("edit-text")) { EditText v = (EditText) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("request-focus")) { v.requestFocus(); InputMethodManager imm = (InputMethodManager) ctx .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); } return; } if (type.equals("button")) { Button v = (Button) vv; if (token.equals("text")) { v.setText(arr.getString(3)); } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("toggle-button")) { ToggleButton v = (ToggleButton) vv; if (token.equals("text")) { v.setText(arr.getString(3)); return; } if (token.equals("checked")) { if (arr.getInt(3) == 0) v.setChecked(false); else v.setChecked(true); return; } if (token.equals("listener")) { final String fn = arr.getString(3); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { m_Scheme.eval("(" + fn + ")"); } }); } return; } if (type.equals("canvas")) { StarwispCanvas v = (StarwispCanvas) vv; if (token.equals("drawlist")) { v.SetDrawList(arr.getJSONArray(3)); } return; } if (type.equals("camera-preview")) { final CameraPreview v = (CameraPreview) vv; if (token.equals("take-picture")) { final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3); v.TakePicture(new PictureCallback() { public void onPictureTaken(byte[] data, Camera camera) { String datetime = getDateTime(); String filename = path + datetime + ".jpg"; SaveData(filename, data); v.Shutdown(); ctx.finish(); } }); } if (token.equals("shutdown")) { v.Shutdown(); } return; } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); if (token.equals("max")) { // android seekbar bug workaround int p = v.getProgress(); v.setMax(0); v.setProgress(0); v.setMax(arr.getInt(3)); v.setProgress(1000); // not working.... :( } } if (type.equals("spinner")) { Spinner v = (Spinner) vv; if (token.equals("selection")) { v.setSelection(arr.getInt(3)); } if (token.equals("array")) { final JSONArray items = arr.getJSONArray(3); ArrayList<String> spinnerArray = new ArrayList<String>(); for (int i = 0; i < items.length(); i++) { spinnerArray.add(items.getString(i)); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, android.R.layout.simple_spinner_item, spinnerArray) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface); return v; } }; v.setAdapter(spinnerArrayAdapter); final int wid = id; // need to update for new values v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { try { CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\""); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } } public void onNothingSelected(AdapterView<?> v) { } }); } return; } } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } }
From source file:com.ywesee.amiko.MainActivity.java
/** * Show soft keyboard/* w w w.j av a 2s.c o m*/ */ private void showSoftKeyboard(int duration) { mSearch.requestFocus(); mSearch.postDelayed(new Runnable() { @Override public void run() { // Display keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mSearch, InputMethodManager.SHOW_IMPLICIT); } }, duration); }
From source file:org.akop.ararat.view.CrosswordView.java
protected void showKeyboard() { if (mInputMode != INPUT_MODE_NONE) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(CrosswordView.this, InputMethodManager.SHOW_IMPLICIT); }//from ww w. jav a 2 s . co m }
From source file:pl.edu.agh.mindmapex.gui.MainActivity.java
private void editContent(final Box myClicked, final AddBox addBox) { final Dialog dialog = DialogFactory.boxContentDialog(MainActivity.this); final Button btn = (Button) dialog.findViewById(R.id.dialogButtonOK); final EditText et = (EditText) dialog.findViewById(R.id.editText); et.requestFocus();//w ww.ja v a 2 s. c o m final Button btn2 = (Button) dialog.findViewById(R.id.button2); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MainActivity.commandsUndo.size() > 1 && MainActivity.commandsUndo.getLast() instanceof AddBox) { MainActivity.commandsUndo.getLast().undo(); MainActivity.commandsUndo.removeLast(); menu.getItem(5).setVisible(false); //lay.invalidate(); //lay.revalidate(); } else if (MainActivity.commandsUndo.size() == 1 && MainActivity.commandsUndo.getFirst() instanceof AddBox) { MainActivity.commandsUndo.getFirst().undo(); MainActivity.commandsUndo.removeFirst(); menu.getItem(5).setVisible(false); //lay.invalidate(); // lay.revalidate(); } dialog.dismiss(); } }); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(et.getWindowToken(), 0); String text = (et.getText().toString()); EditBox editBox = new EditBox(); Properties properties = new Properties(); properties.put("box", myClicked); properties.put("box_text", text); editBox.execute(properties); MainActivity.menu.getItem(5).setVisible(true); if (addBox != null) { addBox.name = myClicked.topic.getTitleText(); } lay.updateBoxWithText(myClicked); dialog.dismiss(); } }); et.setText(myClicked.topic.getTitleText()); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT); dialog.show(); }