List of usage examples for android.widget ToggleButton setChecked
@Override public void setChecked(boolean checked)
From source file:foam.opensauces.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { try {//from www . ja va2 s .c om 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:ru.valle.safetrade.SellActivity.java
private void takeFunds() { String finalAddress = ""; String errorMessage = null;//ww w . j a va 2 s.c o m if (tradeInfo == null) { errorMessage = getString(R.string.state_not_loaded_yet); } else if (TextUtils.isEmpty(tradeInfo.privateKey)) { errorMessage = getString(R.string.no_private_key_from_buyer); } else if (addressState == null) { errorMessage = getString(R.string.alert_checking_balance);//TODO it may be not true because of networking errors, add retry } // } else if (addressState.getBalance() == 0) { // errorMessage = getString(R.string.zero_balance, addressState.address); // } else { CharSequence enteredAddress = finalAddressView.getText(); if (enteredAddress != null) { finalAddress = enteredAddress.toString(); } if (TextUtils.isEmpty(finalAddress)) { errorMessage = getString(R.string.enter_your_final_address); } } if (errorMessage != null) { showAlert(errorMessage); } else { View feesSelectorView = LayoutInflater.from(this).inflate(R.layout.fees_selector, null); assert feesSelectorView != null; TextView descView = (TextView) feesSelectorView.findViewById(R.id.tx_desc); final AddressState addressStateArg; final BTCUtils.PrivateKeyInfo privateKeyInfo; //args // addressStateArg = addressState; // privateKeyInfo = BTCUtils.decodePrivateKey(tradeInfo.privateKey); // try { addressStateArg = new AddressState("1933phfhK3ZgFQNLGSDXvqCn32k2buXY8a", MainActivity.parseUnspentOutputsFromBlockchainInfo(new String( QRCodesProvider.readStream(getResources().openRawResource(R.raw.fakeoutputs))))); privateKeyInfo = BTCUtils.decodePrivateKey(tradeInfo.privateKey); } catch (Exception e) { throw new RuntimeException(); } // final long balance = addressStateArg.getBalance(); descView.setText( getString(R.string.confirm_tx_x_btc_to_addr, BTCUtils.formatValue(balance), finalAddress)); final ToggleButton minFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.min_miner_fee); final ToggleButton safeFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.safe_miner_fee); final ToggleButton maxFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.max_miner_fee); final TextView minersFeeView = (TextView) feesSelectorView.findViewById(R.id.miners_fee); final ToggleButton noDevFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.no_dev_fee); final ToggleButton medDevFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.med_dev_fee); final ToggleButton maxDevFeeButton = (ToggleButton) feesSelectorView.findViewById(R.id.max_dev_fee); final TextView devFeeView = (TextView) feesSelectorView.findViewById(R.id.developer_fee); final TextView txDescFinalView = (TextView) feesSelectorView.findViewById(R.id.tx_desc_after_fees); CompoundButton.OnCheckedChangeListener feesSelectorListener = new CompoundButton.OnCheckedChangeListener() { long fee; long devFee; public int feeLevel; @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { switch (buttonView.getId()) { case R.id.min_miner_fee: { if (isChecked) { safeFeeButton.setChecked(false); maxFeeButton.setChecked(false); updateFee(0); } else if (!safeFeeButton.isChecked() && !maxFeeButton.isChecked()) { buttonView.setChecked(true); } } break; case R.id.safe_miner_fee: { if (isChecked) { minFeeButton.setChecked(false); maxFeeButton.setChecked(false); updateFee(1); } else if (!minFeeButton.isChecked() && !maxFeeButton.isChecked()) { buttonView.setChecked(true); } } break; case R.id.max_miner_fee: { if (isChecked) { minFeeButton.setChecked(false); safeFeeButton.setChecked(false); updateFee(2); } else if (!minFeeButton.isChecked() && !safeFeeButton.isChecked()) { buttonView.setChecked(true); } } break; case R.id.no_dev_fee: { if (isChecked) { medDevFeeButton.setChecked(false); maxDevFeeButton.setChecked(false); updateDevFee(0); } else if (!medDevFeeButton.isChecked() && !maxDevFeeButton.isChecked()) { buttonView.setChecked(true); } } break; case R.id.med_dev_fee: { if (isChecked) { noDevFeeButton.setChecked(false); maxDevFeeButton.setChecked(false); updateDevFee(1); } else if (!noDevFeeButton.isChecked() && !maxDevFeeButton.isChecked()) { buttonView.setChecked(true); } } break; case R.id.max_dev_fee: { if (isChecked) { noDevFeeButton.setChecked(false); medDevFeeButton.setChecked(false); updateDevFee(2); } else if (!noDevFeeButton.isChecked() && !medDevFeeButton.isChecked()) { buttonView.setChecked(true); } } break; } } private void updateDevFee(int level) { devFee = getDevFee(level, balance); devFeeView.setText(getString(R.string.tips_for_dev, BTCUtils.formatValue(devFee))); updateFee(feeLevel); } private void updateFee(int level) { feeLevel = level; fee = getMinerFee(level, devFee, balance, addressStateArg.getUnspentOutputs(), privateKeyInfo.isPublicKeyCompressed); minersFeeView.setText(getString(R.string.miners_fee, BTCUtils.formatValue(fee))); txDescFinalView.setText( getString(R.string.final_tx_desc, BTCUtils.formatValue(balance - fee - devFee))); } }; minFeeButton.setOnCheckedChangeListener(feesSelectorListener); safeFeeButton.setOnCheckedChangeListener(feesSelectorListener); maxFeeButton.setOnCheckedChangeListener(feesSelectorListener); ((ToggleButton) feesSelectorView.findViewById(R.id.no_dev_fee)) .setOnCheckedChangeListener(feesSelectorListener); ((ToggleButton) feesSelectorView.findViewById(R.id.med_dev_fee)) .setOnCheckedChangeListener(feesSelectorListener); ((ToggleButton) feesSelectorView.findViewById(R.id.max_dev_fee)) .setOnCheckedChangeListener(feesSelectorListener); safeFeeButton.setChecked(true); if (getDevFee(1, balance) == 0) { medDevFeeButton.setEnabled(false); maxDevFeeButton.setEnabled(getDevFee(2, balance) > 0); noDevFeeButton.setChecked(true); } else { medDevFeeButton.setChecked(true); } long minDevFee = getDevFee(0, balance); if (getMinerFee(2, minDevFee, balance, addressStateArg.getUnspentOutputs(), privateKeyInfo.isPublicKeyCompressed) == balance - minDevFee) { maxFeeButton.setEnabled(false); } if (getMinerFee(1, minDevFee, balance, addressStateArg.getUnspentOutputs(), privateKeyInfo.isPublicKeyCompressed) == balance - minDevFee) { safeFeeButton.setEnabled(false); minFeeButton.setChecked(true); } new AlertDialog.Builder(SellActivity.this).setView(feesSelectorView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setNegativeButton(android.R.string.cancel, null).show(); } }
From source file:com.updetector.MainActivity.java
/** * Handle Setting click/* www . ja v a 2 s .c o m*/ */ private void handleSettings() { final Dialog dialog = new Dialog(this); dialog.setTitle(R.string.menu_item_settings); dialog.setContentView(R.layout.settings); final SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE); final Editor editor = mPrefs.edit(); final ToggleButton logOnButton = (ToggleButton) dialog.findViewById(R.id.log_on); logOnButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ON, false)); final Button btDeviceSelectButton = (Button) dialog.findViewById(R.id.bt_device_button); btDeviceSelectButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (mBluetoothAdapter.isEnabled()) { selectBluetoothDevice(); } else { Toast.makeText(getApplicationContext(), "Please enable your Bluetooth first.", Toast.LENGTH_SHORT).show(); } } }); final Button applyButton = (Button) dialog.findViewById(R.id.apply_button); final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); applyButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (logOnButton.isChecked()) editor.putBoolean(Constants.LOGGING_ON, true); else editor.putBoolean(Constants.LOGGING_ON, false); editor.commit(); dialog.cancel(); } }); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { dialog.cancel(); } }); dialog.show(); }
From source file:com.updetector.MainActivity.java
/** * Handle Performance Tuning Click/*from w w w . j ava2s .co m*/ */ private void handleAdvancedSetting() { final Dialog dialog = new Dialog(this); dialog.setTitle(R.string.menu_item_advanced_settings); dialog.setContentView(R.layout.advanced_setting); final SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE); final Editor editor = mPrefs.edit(); final ToggleButton classifierForCIVOnButton = (ToggleButton) dialog.findViewById(R.id.civ_classifier_on); classifierForCIVOnButton.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, false)); final ToggleButton isOutdoorButton = (ToggleButton) dialog.findViewById(R.id.is_outdoor); isOutdoorButton.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, false)); final EditText notificationTresholdText = (EditText) dialog.findViewById(R.id.notification_threshold); notificationTresholdText .setText(String.format("%.2f", mPrefs.getFloat(Constants.PREFERENCE_KEY_NOTIFICATION_THRESHOLD, (float) Constants.DEFAULT_DETECTION_THRESHOLD))); //final EditText detectionIntervalText=(EditText)dialog.findViewById(R.id.detection_interval); //detectionIntervalText.setText(String.valueOf(mPrefs.getInt(Constants.PREFERENCE_KEY_DETECTION_INTERVAL, Constants.DETECTION_INTERVAL_DEFAULT_VALUE) )); final EditText googleActivityUpdateIntervalText = (EditText) dialog .findViewById(R.id.google_activity_update_interval); googleActivityUpdateIntervalText .setText(String.valueOf(mPrefs.getInt(Constants.PREFERENCE_KEY_GOOGLE_ACTIVITY_UPDATE_INTERVAL, Constants.GOOGLE_ACTIVITY_UPDATE_INTERVAL_DEFAULT_VALUE))); //final ToggleButton useGoogleActivityInFusion=(ToggleButton)dialog.findViewById(R.id.use_google_for_motion_state_in_fusion); //useGoogleActivityInFusion.setChecked(mPrefs.getBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, false)); final ToggleButton logAcclRawButton = (ToggleButton) dialog.findViewById(R.id.log_raw_switch); logAcclRawButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, false)); final ToggleButton logGoogleActUpdatesButton = (ToggleButton) dialog .findViewById(R.id.log_google_updates_switch); logGoogleActUpdatesButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, false)); final ToggleButton logDetectionButton = (ToggleButton) dialog.findViewById(R.id.log_report_switch); logDetectionButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_DETECTION_SWITCH, false)); final ToggleButton logErrorButton = (ToggleButton) dialog.findViewById(R.id.log_error_switch); logErrorButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ERROR_SWITCH, true)); //final EditText deltaForConditionalProb=(EditText)dialog.findViewById(R.id.normal_dist_delta); //deltaForConditionalProb.setText(String.valueOf(mPrefs.getFloat(Constants.CIV_DELTA_CONDITIONAL_PROBABILITY, 2)) ); final Button applyButton = (Button) dialog.findViewById(R.id.performance_apply_button); final Button cancelButton = (Button) dialog.findViewById(R.id.peformance_cancel_button); applyButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (classifierForCIVOnButton.isChecked()) editor.putBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, true); else editor.putBoolean(Constants.PREFERENCE_KEY_CIV_CLASSIFIER_ON, false); if (isOutdoorButton.isChecked()) editor.putBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, true); else editor.putBoolean(Constants.PREFERENCE_KEY_IS_OUTDOOR, false); if (logAcclRawButton.isChecked()) editor.putBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, true); else editor.putBoolean(Constants.LOGGING_ACCL_RAW_SWITCH, false); if (logGoogleActUpdatesButton.isChecked()) editor.putBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, true); else editor.putBoolean(Constants.LOGGING_GOOGLE_ACTIVITY_UPDATE, false); if (logDetectionButton.isChecked()) editor.putBoolean(Constants.LOGGING_DETECTION_SWITCH, true); else editor.putBoolean(Constants.LOGGING_DETECTION_SWITCH, false); if (logErrorButton.isChecked()) editor.putBoolean(Constants.LOGGING_ERROR_SWITCH, true); else editor.putBoolean(Constants.LOGGING_ERROR_SWITCH, false); float notificationTreshold; try { notificationTreshold = Float.parseFloat(notificationTresholdText.getText().toString()); } catch (Exception ex) { notificationTreshold = (float) Constants.DEFAULT_DETECTION_THRESHOLD; } editor.putFloat(Constants.PREFERENCE_KEY_NOTIFICATION_THRESHOLD, notificationTreshold); /*int detectionInterval; try{ detectionInterval=Integer.parseInt( detectionIntervalText.getText().toString()); }catch(Exception ex){ detectionInterval=Constants.DETECTION_INTERVAL_DEFAULT_VALUE; } editor.putInt(Constants.PREFERENCE_KEY_DETECTION_INTERVAL, detectionInterval);*/ /*if (useGoogleActivityInFusion.isChecked()) editor.putBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, true); else editor.putBoolean(Constants.PREFERENCE_KEY_USE_GOOGLE_ACTIVITY_IN_FUSION, false);*/ int googleActivityUpdateInterval; try { googleActivityUpdateInterval = Integer .parseInt(googleActivityUpdateIntervalText.getText().toString()); } catch (Exception ex) { googleActivityUpdateInterval = Constants.GOOGLE_ACTIVITY_UPDATE_INTERVAL_DEFAULT_VALUE; } editor.putInt(Constants.PREFERENCE_KEY_GOOGLE_ACTIVITY_UPDATE_INTERVAL, googleActivityUpdateInterval); /*try{ Float delta=Float.parseFloat(deltaForConditionalProb.getText().toString()); editor.putFloat(Constants.CIV_DELTA_CONDITIONAL_PROBABILITY, delta); }catch(Exception ex){ Toast.makeText(getApplicationContext(), "Input must be a float number", Toast.LENGTH_SHORT).show(); }*/ editor.commit(); dialog.cancel(); } }); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { dialog.cancel(); } }); dialog.show(); }
From source file:ru.valle.btc.MainActivity.java
private void showQRCodePopupForPrivateKey(final String label, final String address, final String[] data, final String[] dataTypes) { DisplayMetrics dm = getResources().getDisplayMetrics(); final int screenSize = Math.min(dm.widthPixels, dm.heightPixels); new AsyncTask<Void, Void, Bitmap[]>() { @Override/*from w ww. j ava 2 s.c om*/ protected Bitmap[] doInBackground(Void... params) { Bitmap[] result = new Bitmap[data.length]; for (int i = 0; i < data.length; i++) { if (data[i] != null) { QRCode qr = QRCode.getMinimumQRCode(data[i], ErrorCorrectLevel.M); result[i] = qr.createImage(screenSize / 2); } } return result; } @Override protected void onPostExecute(final Bitmap[] bitmap) { if (bitmap != null) { View view = getLayoutInflater().inflate(R.layout.private_key_qr, mainLayout, false); if (view != null) { final ToggleButton toggle1 = (ToggleButton) view.findViewById(R.id.toggle_1); final ToggleButton toggle2 = (ToggleButton) view.findViewById(R.id.toggle_2); final ToggleButton toggle3 = (ToggleButton) view.findViewById(R.id.toggle_3); final ImageView qrView = (ImageView) view.findViewById(R.id.qr_code_image); final TextView dataView = (TextView) view.findViewById(R.id.qr_code_data); if (data[0] == null) { toggle1.setVisibility(View.GONE); } else { toggle1.setTextOff(dataTypes[0]); toggle1.setTextOn(dataTypes[0]); toggle1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle2.setChecked(false); toggle3.setChecked(false); qrView.setImageBitmap(bitmap[0]); dataView.setText(data[0]); } else if (!toggle2.isChecked() && !toggle3.isChecked()) { buttonView.setChecked(true); } } }); } if (data[1] == null) { toggle2.setVisibility(View.GONE); } else { toggle2.setTextOff(dataTypes[1]); toggle2.setTextOn(dataTypes[1]); toggle2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle1.setChecked(false); toggle3.setChecked(false); qrView.setImageBitmap(bitmap[1]); dataView.setText(data[1]); } else if (!toggle1.isChecked() && !toggle3.isChecked()) { buttonView.setChecked(true); } } }); } if (data[2] == null) { toggle3.setVisibility(View.GONE); } else { toggle3.setTextOff(dataTypes[2]); toggle3.setTextOn(dataTypes[2]); toggle3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle1.setChecked(false); toggle2.setChecked(false); qrView.setImageBitmap(bitmap[2]); dataView.setText(data[2]); } else if (!toggle1.isChecked() && !toggle2.isChecked()) { buttonView.setChecked(true); } } }); } if (data[2] != null) { toggle3.setChecked(true); } else if (data[0] != null) { toggle1.setChecked(true); } else { toggle2.setChecked(true); } AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(label); builder.setView(view); DialogInterface.OnClickListener shareClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int selectedIndex; if (toggle1.isChecked()) { selectedIndex = 0; } else if (toggle2.isChecked()) { selectedIndex = 1; } else { selectedIndex = 2; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, label); intent.putExtra(Intent.EXTRA_TEXT, data[selectedIndex]); startActivity( Intent.createChooser(intent, getString(R.string.share_chooser_title))); } }; if (systemSupportsPrint()) { builder.setPositiveButton(R.string.print, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int selectedIndex; if (toggle1.isChecked()) { selectedIndex = 0; } else if (toggle2.isChecked()) { selectedIndex = 1; } else { selectedIndex = 2; } Renderer.printWallet(MainActivity.this, label, SCHEME_BITCOIN + address, data[selectedIndex]); } }); builder.setNeutralButton(R.string.share, shareClickListener); } else { builder.setPositiveButton(R.string.share, shareClickListener); } builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } } } }.execute(); }
From source file:foam.starwisp.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { String type = ""; Integer tid = 0;//ww w.j a v a2s. c om String token = ""; try { type = arr.getString(0); tid = arr.getInt(1); token = arr.getString(2); } catch (JSONException e) { Log.e("starwisp", "Error parsing update arguments for " + ctxname + " " + arr.toString() + e.toString()); } final Integer id = tid; //Log.i("starwisp", "Update: "+type+" "+id+" "+token); try { // non widget commands if (token.equals("toast")) { Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT); LinearLayout linearLayout = (LinearLayout) msg.getView(); View child = linearLayout.getChildAt(0); TextView messageTextView = (TextView) child; messageTextView.setTextSize(arr.getInt(4)); 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("soundfile-start-recording")) { String filename = arr.getString(3); m_SoundManager.StartRecording(filename); } if (token.equals("soundfile-stop-recording")) { m_SoundManager.StopRecording(); } if (token.equals("soundfile-start-playback")) { String filename = arr.getString(3); m_SoundManager.StartPlaying(filename); } if (token.equals("soundfile-stop-playback")) { m_SoundManager.StopPlaying(); } 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.fragment_slide_left_enter, // R.animator.fragment_slide_right_exit); //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("view")) { //ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse())); File f = new File(arr.getString(3)); Uri fileUri = Uri.fromFile(f); Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW); String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(arr.getString(3)); String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); myIntent.setDataAndType(fileUri, mimetype); ctx.startActivity(myIntent); 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, arr.getInt(5), arr.getInt(6)); return; } if (token.equals("sensors-get")) { final String name = arr.getString(3); if (m_SensorHandler == null) { m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this); } m_SensorHandler.GetSensors((StarwispActivity) ctx, name, this); return; } if (token.equals("sensors-start")) { final String name = arr.getString(3); final JSONArray requested_json = arr.getJSONArray(5); ArrayList<Integer> requested = new ArrayList<Integer>(); try { for (int i = 0; i < requested_json.length(); i++) { requested.add(requested_json.getInt(i)); } } catch (JSONException e) { Log.e("starwisp", "Error parsing data in sensors start " + e.toString()); } // start it up... if (m_SensorHandler == null) { m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this); } m_SensorHandler.StartSensors((StarwispActivity) ctx, name, this, requested); return; } if (token.equals("sensors-stop")) { if (m_SensorHandler != null) { m_SensorHandler.StopSensors(); } 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).replace("\\", "")); 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")) { Log.i("starwisp", "http-request called"); 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-post")) { Log.i("starwisp", "http-post called"); 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); final String data = arr.getString(6); m_NetworkManager.StartRequestThread(url, "post", data, name); } return; } if (token.equals("http-upload")) { if (m_NetworkManager.state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "attempting http ul request"); final String filename = arr.getString(4); final String url = arr.getString(5); m_NetworkManager.StartRequestThread(url, "upload", "", filename); } 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("take-photo")) { photo(ctx, arr.getString(3), arr.getInt(4)); } if (token.equals("bluetooth")) { final String name = arr.getString(3); m_Bluetooth.Start((StarwispActivity) ctx, name, this); return; } if (token.equals("bluetooth-send")) { m_Bluetooth.Write(arr.getString(3)); } if (token.equals("process-image-in-place")) { BitmapCache.ProcessInPlace(arr.getString(3)); } 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("ok-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("Ok", 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; } /////////////////////////////////////////////////////////// if (id == 0) { Log.i("starwisp", "Zero ID, aborting..."); return; } // now try and find the widget final 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; } // only tested on spinners if (token.equals("disabled")) { vv.setAlpha(0.3f); //vv.getSelectedView().setEnabled(false); vv.setEnabled(false); return; } if (token.equals("enabled")) { vv.setAlpha(1.0f); //vv.getSelectedView().setEnabled(true); vv.setEnabled(true); return; } if (token.equals("animate")) { JSONArray trans = arr.getJSONArray(3); final TranslateAnimation animation = new TranslateAnimation(getPixelsFromDp(ctx, trans.getInt(0)), getPixelsFromDp(ctx, trans.getInt(1)), getPixelsFromDp(ctx, trans.getInt(2)), getPixelsFromDp(ctx, trans.getInt(3))); animation.setDuration(1000); animation.setFillAfter(false); animation.setInterpolator(new AnticipateOvershootInterpolator(1.0f)); animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { vv.clearAnimation(); Log.i("starwisp", "animation end"); ((ViewManager) vv.getParent()).removeView(vv); //LayoutParams lp = new LayoutParams(imageView.getWidth(), imageView.getHeight()); //lp.setMargins(50, 100, 0, 0); //imageView.setLayoutParams(lp); } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { Log.i("starwisp", "animation start"); } }); vv.startAnimation(animation); return; } // tokens that work on everything if (token.equals("set-enabled")) { Log.i("starwisp", "set-enabled called..."); vv.setEnabled(arr.getInt(3) == 1); vv.setClickable(arr.getInt(3) == 1); if (vv.getBackground() != null) { if (arr.getInt(3) == 0) { //vv.setBackgroundColor(0x00000000); vv.getBackground().setColorFilter(0x20000000, PorterDuff.Mode.MULTIPLY); } else { vv.getBackground().setColorFilter(null); } } return; } if (token.equals("background-colour")) { JSONArray col = arr.getJSONArray(3); if (type.equals("linear-layout")) { vv.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2))); } else { //vv.setBackgroundColor(); vv.getBackground().setColorFilter( Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)), PorterDuff.Mode.MULTIPLY); } vv.invalidate(); return; } // special cases if (type.equals("linear-layout")) { //Log.i("starwisp","linear-layout update id: "+id); StarwispLinearLayout.Update(this, (LinearLayout) vv, token, ctx, ctxname, arr); return; } if (type.equals("relative-layout")) { StarwispRelativeLayout.Update(this, (RelativeLayout) vv, token, ctx, ctxname, arr); return; } 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 (token.equals("contents-add")) { 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); 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 on click 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 pages 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")) { v.setImageBitmap(BitmapCache.Load(arr.getString(3))); } 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(Html.fromHtml(arr.getString(3)), BufferType.SPANNABLE); // v.invalidate(); } if (token.equals("file")) { v.setText(LoadData(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[] input, Camera camera) { Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length); Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true); ByteArrayOutputStream blob = new ByteArrayOutputStream(); resized.compress(Bitmap.CompressFormat.JPEG, 100, blob); String datetime = getDateTime(); String filename = path + datetime + ".jpg"; SaveData(filename, blob.toByteArray()); v.Shutdown(); ctx.finish(); } }); } // don't shut the activity down and use provided path if (token.equals("take-picture-cont")) { final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3); Log.i("starwisp", "take-picture-cont fired"); v.TakePicture(new PictureCallback() { public void onPictureTaken(byte[] input, Camera camera) { Log.i("starwisp", "on picture taken..."); // the version used by the uav app Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length); //Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true); ByteArrayOutputStream blob = new ByteArrayOutputStream(); original.compress(Bitmap.CompressFormat.JPEG, 95, blob); original.recycle(); String filename = path; Log.i("starwisp", path); SaveData(filename, blob.toByteArray()); // burn gps into exif data if (m_GPS.currentLocation != null) { double latitude = m_GPS.currentLocation.getLatitude(); double longitude = m_GPS.currentLocation.getLongitude(); try { ExifInterface exif = new ExifInterface(filename); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPS.convert(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, GPS.latitudeRef(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPS.convert(longitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, GPS.longitudeRef(longitude)); exif.saveAttributes(); } catch (IOException e) { Log.i("starwisp", "Couldn't open " + filename + " to add exif data: ioexception caught."); } } v.TakenPicture(); } }); } 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, R.layout.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; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); 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) { CallbackArgs(ctx, ctxname, wid, "" + pos); } public void onNothingSelected(AdapterView<?> v) { } }); } return; } if (type.equals("draw-map")) { DrawableMap v = m_DMaps.get(id); if (v != null) { if (token.equals("polygons")) { v.UpdateFromJSON(arr.getJSONArray(3)); } if (token.equals("centre")) { JSONArray tokens = arr.getJSONArray(3); v.Centre(tokens.getDouble(0), tokens.getDouble(1), tokens.getInt(2)); } if (token.equals("layout")) { v.m_parent.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); } } else { Log.e("starwisp", "Asked to update a drawmap which doesn't exist"); } } } catch (JSONException e) { Log.e("starwisp", "Error parsing builder data " + e.toString()); Log.e("starwisp", "type:" + type + " id:" + id + " token:" + token); } }
From source file:cm.aptoide.pt.MainActivity.java
private void displayOptionsDialog() { final SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(this); final Editor editor = sPref.edit(); View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_order_popup, null); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(view); final AlertDialog orderDialog = dialogBuilder.create(); orderDialog.setIcon(android.R.drawable.ic_menu_sort_by_size); orderDialog.setTitle(getString(R.string.menu_display_options)); orderDialog.setCancelable(true);/*from w w w .ja v a 2s .com*/ final RadioButton ord_rct = (RadioButton) view.findViewById(R.id.org_rct); final RadioButton ord_abc = (RadioButton) view.findViewById(R.id.org_abc); final RadioButton ord_rat = (RadioButton) view.findViewById(R.id.org_rat); final RadioButton ord_dwn = (RadioButton) view.findViewById(R.id.org_dwn); final RadioButton ord_price = (RadioButton) view.findViewById(R.id.org_price); final RadioButton btn1 = (RadioButton) view.findViewById(R.id.shw_ct); final RadioButton btn2 = (RadioButton) view.findViewById(R.id.shw_all); final ToggleButton adult = (ToggleButton) view.findViewById(R.id.adultcontent_toggle); orderDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() { boolean pop_change = false; private boolean pop_change_category = false; public void onClick(DialogInterface dialog, int which) { if (ord_rct.isChecked()) { pop_change = true; order = Order.DATE; } else if (ord_abc.isChecked()) { pop_change = true; order = Order.NAME; } else if (ord_rat.isChecked()) { pop_change = true; order = Order.RATING; } else if (ord_dwn.isChecked()) { pop_change = true; order = Order.DOWNLOADS; } else if (ord_price.isChecked()) { pop_change = true; order = Order.PRICE; } if (btn1.isChecked()) { pop_change = true; pop_change_category = true; editor.putBoolean("orderByCategory", true); } else if (btn2.isChecked()) { pop_change = true; pop_change_category = true; editor.putBoolean("orderByCategory", false); } if (adult.isChecked()) { pop_change = true; editor.putBoolean("matureChkBox", false); } else { editor.putBoolean("matureChkBox", true); } if (pop_change) { editor.putInt("order_list", order.ordinal()); editor.commit(); if (pop_change_category) { if (!depth.equals(ListDepth.CATEGORY1) && !depth.equals(ListDepth.STORES)) { if (depth.equals(ListDepth.APPLICATIONS)) { removeLastBreadCrumb(); } removeLastBreadCrumb(); depth = ListDepth.CATEGORY1; } } redrawAll(); refreshAvailableList(true); } } }); if (sPref.getBoolean("orderByCategory", false)) { btn1.setChecked(true); } else { btn2.setChecked(true); } if (!ApplicationAptoide.MATURECONTENTSWITCH) { adult.setVisibility(View.GONE); view.findViewById(R.id.dialog_adult_content_label).setVisibility(View.GONE); } adult.setChecked(!sPref.getBoolean("matureChkBox", false)); // adult.setOnCheckedChangeListener(adultCheckedListener); switch (order) { case DATE: ord_rct.setChecked(true); break; case DOWNLOADS: ord_dwn.setChecked(true); break; case NAME: ord_abc.setChecked(true); break; case RATING: ord_rat.setChecked(true); break; case PRICE: ord_price.setChecked(true); break; default: break; } orderDialog.show(); }