List of usage examples for android.widget EditText getText
@Override
public Editable getText()
From source file:im.vector.util.BugReporter.java
/** * Send a bug report either with email or with Vector. *//*w ww. j av a2 s.c o m*/ public static void sendBugReport() { final Activity currentActivity = VectorApp.getCurrentActivity(); // no current activity so cannot display an alert if (null == currentActivity) { sendBugReport(VectorApp.getInstance().getApplicationContext(), true, true, "", null); return; } final Context appContext = currentActivity.getApplicationContext(); LayoutInflater inflater = currentActivity.getLayoutInflater(); View dialogLayout = inflater.inflate(R.layout.dialog_bug_report, null); final AlertDialog.Builder dialog = new AlertDialog.Builder(currentActivity); dialog.setTitle(R.string.send_bug_report); dialog.setView(dialogLayout); final EditText bugReportText = (EditText) dialogLayout.findViewById(R.id.bug_report_edit_text); final CheckBox includeLogsButton = (CheckBox) dialogLayout .findViewById(R.id.bug_report_button_include_logs); final CheckBox includeCrashLogsButton = (CheckBox) dialogLayout .findViewById(R.id.bug_report_button_include_crash_logs); final ProgressBar progressBar = (ProgressBar) dialogLayout.findViewById(R.id.bug_report_progress_view); final TextView progressTextView = (TextView) dialogLayout.findViewById(R.id.bug_report_progress_text_view); dialog.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // will be overridden to avoid dismissing the dialog while displaying the progress } }); dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // will be overridden to avoid dismissing the dialog while displaying the progress } }); // final AlertDialog bugReportDialog = dialog.show(); final Button cancelButton = bugReportDialog.getButton(AlertDialog.BUTTON_NEGATIVE); final Button sendButton = bugReportDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (null != cancelButton) { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // check if there is no upload in progress if (includeLogsButton.isEnabled()) { bugReportDialog.dismiss(); } else { mIsCancelled = true; cancelButton.setEnabled(false); } } }); } if (null != sendButton) { sendButton.setEnabled(false); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // disable the active area while uploading the bug report bugReportText.setEnabled(false); sendButton.setEnabled(false); includeLogsButton.setEnabled(false); includeCrashLogsButton.setEnabled(false); progressTextView.setVisibility(View.VISIBLE); progressTextView.setText(appContext.getString(R.string.send_bug_report_progress, 0 + "")); progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(0); sendBugReport(VectorApp.getInstance(), includeLogsButton.isChecked(), includeCrashLogsButton.isChecked(), bugReportText.getText().toString(), new IMXBugReportListener() { @Override public void onUploadFailed(String reason) { try { if (null != VectorApp.getInstance() && !TextUtils.isEmpty(reason)) { Toast.makeText(VectorApp.getInstance(), VectorApp.getInstance() .getString(R.string.send_bug_report_failed, reason), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e(LOG_TAG, "## onUploadFailed() : failed to display the toast " + e.getMessage()); } try { // restore the dialog if the upload failed bugReportText.setEnabled(true); sendButton.setEnabled(true); includeLogsButton.setEnabled(true); includeCrashLogsButton.setEnabled(true); cancelButton.setEnabled(true); progressTextView.setVisibility(View.GONE); progressBar.setVisibility(View.GONE); } catch (Exception e) { Log.e(LOG_TAG, "## onUploadFailed() : failed to restore the dialog button " + e.getMessage()); try { bugReportDialog.dismiss(); } catch (Exception e2) { Log.e(LOG_TAG, "## onUploadFailed() : failed to dismiss the dialog " + e2.getMessage()); } } mIsCancelled = false; } @Override public void onUploadCancelled() { onUploadFailed(null); } @Override public void onProgress(int progress) { if (progress > 100) { Log.e(LOG_TAG, "## onProgress() : progress > 100"); progress = 100; } else if (progress < 0) { Log.e(LOG_TAG, "## onProgress() : progress < 0"); progress = 0; } progressBar.setProgress(progress); progressTextView.setText( appContext.getString(R.string.send_bug_report_progress, progress + "")); } @Override public void onUploadSucceed() { try { if (null != VectorApp.getInstance()) { Toast.makeText(VectorApp.getInstance(), VectorApp.getInstance().getString( R.string.send_bug_report_sent), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the toast " + e.getMessage()); } try { bugReportDialog.dismiss(); } catch (Exception e) { Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the dialog " + e.getMessage()); } } }); } }); } bugReportText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (null != sendButton) { sendButton.setEnabled(bugReportText.getText().toString().length() > 10); } } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to allow user to select which row to add the shortcut. For * TV channels let the user change the channel name. * //from w ww . j a va 2s .c o m * @see InstallShortcutReceiver * * @param context * @param name * @param icon * @param uri */ public static void displayShortcutsRowSelection(final Launcher context, final String name, final String icon, final String uri) { if (uri == null) { return; } final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); final boolean isChannel = uri.startsWith("tv"); dialog.setContentView(R.layout.select_row); final TextView channelTextView = (TextView) dialog.findViewById(R.id.channelText); final EditText channelNameEditText = (EditText) dialog.findViewById(R.id.channelName); if (isChannel) { channelTextView.setVisibility(View.VISIBLE); channelNameEditText.setVisibility(View.VISIBLE); channelNameEditText.setText(name); } final TextView selectTextView = (TextView) dialog.findViewById(R.id.selectText); selectTextView.setText(context.getString(R.string.dialog_select_row, name)); final Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); spinner.setVisibility(View.GONE); } }); List<String> list = new ArrayList<String>(); final ArrayList<RowInfo> rows = RowsTable.getRows(context); if (rows != null) { for (RowInfo row : rows) { list.add(row.getTitle()); } } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); Button buttonYes = (Button) dialog.findViewById(R.id.buttonOk); buttonYes.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String shortcutName = name; try { if (isChannel) { String channelName = channelNameEditText.getText().toString().trim(); if (channelName.length() == 0) { channelNameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_channel_name_alert)); return; } shortcutName = channelName; } // if the new row radio button is selected, the user must // enter a name for the new row String rowName = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && rowName.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); int rowId = 0; int rowPosition = 0; if (currentRow) { if (rows != null) { String selectedRow = (String) spinner.getSelectedItem(); for (RowInfo row : rows) { if (row.getTitle().equals(selectedRow)) { rowId = row.getId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row break; } } } } else { rowId = (int) RowsTable.insertRow(context, rowName, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); ItemsTable.insertItem(context, rowId, rowPosition, shortcutName, intent, icon, DatabaseHelper.SHORTCUT_TYPE); Toast.makeText(context, context.getString(R.string.shortcut_installed, shortcutName), Toast.LENGTH_SHORT).show(); context.reloadAllGalleries(); if (currentRow) { Analytics.logEvent(Analytics.ADD_SHORTCUT); } else { Analytics.logEvent(Analytics.ADD_SHORTCUT_WITH_ROW); } } catch (Exception e) { Log.d(LOG_TAG, "onClick", e); } context.showCover(false); dialog.dismiss(); } }); Button buttonNo = (Button) dialog.findViewById(R.id.buttonCancel); buttonNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_SHORTCUT); }
From source file:com.zen.androidhtmleditor.AHEActivity.java
@SuppressLint("NewApi") @Override//from w w w . ja va 2s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); setContentView(R.layout.main); SystemBarTintManager tintManager = new SystemBarTintManager(this); // enable status bar tint tintManager.setStatusBarTintEnabled(true); tintManager.setTintColor(Color.parseColor("#4acab4")); SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); Settings.init(settings); //Uncomment this for non Market installs. This will allow version checking. //new Version(this,getVersionName(this,DeveloperToolsActivity.class),"http://androidhtmleditor.com/version.php").execute(); deviceId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID); getOverflowMenu(); getActionBar().setIcon(R.drawable.icon_white); tabactivity = (TabActivity) this; tabHost = tabactivity.getTabHost(); hsv = (HorizontalScrollView) tabactivity.findViewById(R.id.topmenu); mLicenseCheckerCallback = new MyLicenseCheckerCallback(); mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, new AESObfuscator(SALT, getPackageName(), deviceId)), BASE64_PUBLIC_KEY // Your public licensing key. ); mHandler = new Handler(); // doCheck(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (LinearLayout) findViewById(R.id.l1); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle("File(s)"); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle("Server"); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onButtonClickEvent(v); } }); Button disconnect_button = (Button) findViewById(R.id.disconnect_button); disconnect_button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { disconnect(); } }); /* Button button2 = (Button)findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { hsv.setVisibility(View.GONE); v.setVisibility(View.GONE); RelativeLayout rl = (RelativeLayout)v.getParent(); Button button1 = (Button)findViewById(R.id.button1); button1.setVisibility(View.VISIBLE); Button button3 = (Button)findViewById(R.id.button3); button3.setVisibility(View.VISIBLE); ImageView logo = (ImageView)findViewById(R.id.logo); logo.setVisibility(View.VISIBLE); TextView slogan = (TextView)findViewById(R.id.appSlogan); slogan.setVisibility(View.VISIBLE); ScrollView frontLayout = (ScrollView)findViewById(R.id.front); frontLayout.setVisibility(View.VISIBLE); TextView appTitle = (TextView)findViewById(R.id.appTitle); appTitle.setVisibility(View.VISIBLE); Button backButton = (Button)rl.findViewById(R.id.backButton); backButton.setVisibility(View.GONE); arrayAdapter.clear(); arrayAdapter.notifyDataSetChanged(); TextView pathInfo = (TextView)rl.findViewById(R.id.path); pathInfo.setText(""); folderPath = ""; //new MyFetchTask("zenstudio.com.au", "zenstudi", ".-x$%Wmd5b#C","folder",folderPath).execute(); connectedTo = -1; Toast.makeText(AHEActivity.this, "Disconnected", Toast.LENGTH_SHORT).show(); } });*/ Button button3 = (Button) findViewById(R.id.button3); button3.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent SettingsIntent = new Intent(AHEActivity.this, Settings.class); startActivity(SettingsIntent); } }); /*Button backButton = (Button)findViewById(R.id.backButton); backButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String[] pathBits = folderPath.split("/"); folderPath = ""; for(int i=0;i<pathBits.length-1;i++){ folderPath += pathBits[i]+"/"; } arrayAdapter.clear(); //connectedTo SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); String currentServers = settings.getString("Accounts", ""); if(currentServers.equals("")){}else{ Gson gson = new Gson(); SearchResponse response = gson.fromJson(currentServers, SearchResponse.class); List<Result> results = response.data; Result l = results.get(connectedTo); if(l.serverName!="" && l.userName!="" && l.port.trim()!=""){ if(l.sftp.equals("0") || l.sftp.equals("1") || l.sftp.equals("2")){ new MyFetchTask(l.serverName, l.userName, l.passWord,"folder",folderPath,l.sftp,l.port).execute(); }else if(l.sftp.equals("3")){ new FetchSSLTask(l.serverName, l.userName, l.passWord,"folder",folderPath,l.sftp,l.port).execute(); } } } } });*/ TextView pathInfo = (TextView) findViewById(R.id.path); pathInfo.setText(folderPath); lstTest = (ListView) findViewById(R.id.list); // lstTest.setDividerHeight(10); lstTest.setPadding(0, 5, 0, 5); alrts = new ArrayList<String[]>(); arrayAdapter = new FetchAdapter(AHEActivity.this, R.layout.listitems, alrts); lstTest.setAdapter(arrayAdapter); lstTest.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) { final View d = v; final CharSequence[] items = { "Delete", "Rename", "Chmod", "Download" }; TextView t = (TextView) v.findViewById(R.id.fileFolderName); final String oldName = t.getText().toString(); final int position = pos; AlertDialog.Builder builder = new AlertDialog.Builder(AHEActivity.this); builder.setTitle("Choose Action"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { AlertDialog.Builder dbuilder = new AlertDialog.Builder(AHEActivity.this); dbuilder.setMessage("Delete this file?").setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { deleteFile(d); dialog.cancel(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog dalert = dbuilder.create(); dalert.show(); } else if (item == 1) { final Dialog renameDialog = new Dialog(AHEActivity.this); renameDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); renameDialog.setContentView(R.layout.renamediag); renameDialog.setCancelable(true); Button closeServer = (Button) renameDialog.findViewById(R.id.closeServer); closeServer.setOnClickListener(new OnClickListener() { public void onClick(View v) { renameDialog.cancel(); } }); Button saveServer = (Button) renameDialog.findViewById(R.id.saveServer); saveServer.setOnClickListener(new OnClickListener() { public void onClick(View v) { EditText themeUrl = (EditText) renameDialog.findViewById(R.id.themeLink); String newName = themeUrl.getText().toString(); //connectedTo SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); String currentServers = settings.getString("Accounts", ""); if (currentServers.equals("")) { } else { Gson gson = new Gson(); SearchResponse response = gson.fromJson(currentServers, SearchResponse.class); List<Result> results = response.data; Result l = results.get(connectedTo); if (l.serverName != "" && l.userName != "" && l.port.trim() != "") { new RenameTask(l.serverName, l.userName, l.passWord, oldName, newName, folderPath, l.sftp, l.port, position).execute(); renameDialog.cancel(); } } } }); renameDialog.show(); } else if (item == 2) { final Dialog chmodDialog = new Dialog(AHEActivity.this); chmodDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); chmodDialog.setContentView(R.layout.chmoddiag); chmodDialog.setCancelable(true); Button closeServer = (Button) chmodDialog.findViewById(R.id.closeServer); closeServer.setOnClickListener(new OnClickListener() { public void onClick(View v) { chmodDialog.cancel(); } }); Button saveServer = (Button) chmodDialog.findViewById(R.id.saveServer); saveServer.setOnClickListener(new OnClickListener() { public void onClick(View v) { EditText themeUrl = (EditText) chmodDialog.findViewById(R.id.themeLink); String perms = themeUrl.getText().toString(); //connectedTo SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); String currentServers = settings.getString("Accounts", ""); if (currentServers.equals("")) { } else { Gson gson = new Gson(); SearchResponse response = gson.fromJson(currentServers, SearchResponse.class); List<Result> results = response.data; Result l = results.get(connectedTo); if (l.serverName != "" && l.userName != "" && l.port.trim() != "") { if (l.sftp.equals("0") || l.sftp.equals("1") || l.sftp.equals("2")) { new ChmodTask(l.serverName, l.userName, l.passWord, oldName, perms, folderPath, l.sftp, l.port, position).execute(); } else { Toast.makeText(AHEActivity.this, "CHMOD could not be performed on your server via sftp", Toast.LENGTH_SHORT).show(); } chmodDialog.cancel(); } } } }); chmodDialog.show(); } else if (item == 3) { //Make new class to download a file SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); String currentServers = settings.getString("Accounts", ""); if (currentServers.equals("")) { } else { Gson gson = new Gson(); SearchResponse response = gson.fromJson(currentServers, SearchResponse.class); List<Result> results = response.data; Result l = results.get(connectedTo); if (l.serverName != "" && l.userName != "" && l.port.trim() != "") { if (l.sftp.equals("0") || l.sftp.equals("1") || l.sftp.equals("2")) { new DlTask(l.serverName, l.userName, l.passWord, oldName, l.sftp, l.port) .execute(); } } } } //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); } }); AlertDialog alert = builder.create(); alert.show(); return true; } }); lstTest.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> av, View v, int pos, long id) { loadFileFolder(v); } }); }
From source file:de.baumann.hhsmoodle.activities.Activity_todo.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); toDo_title = sharedPref.getString("toDo_title", ""); String toDo_text = sharedPref.getString("toDo_text", ""); toDo_icon = sharedPref.getString("toDo_icon", ""); toDo_create = sharedPref.getString("toDo_create", ""); todo_attachment = sharedPref.getString("toDo_attachment", ""); if (!sharedPref.getString("toDo_seqno", "").isEmpty()) { toDo_seqno = Integer.parseInt(sharedPref.getString("toDo_seqno", "")); }/*from w w w .ja va2 s .com*/ setContentView(R.layout.activity_todo); setTitle(toDo_title); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); helper_main.onStart(Activity_todo.this); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } try { FileOutputStream fOut = new FileOutputStream(newFile()); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(toDo_text); myOutWriter.close(); fOut.flush(); fOut.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } lvItems = (ListView) findViewById(R.id.lvItems); items = new ArrayList<>(); readItems(); itemsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items); lvItems.setAdapter(itemsAdapter); lvItems.post(new Runnable() { public void run() { lvItems.setSelection(lvItems.getCount() - 1); } }); setupListViewListener(); final EditText etNewItem = (EditText) findViewById(R.id.etNewItem); ImageButton ib_paste = (ImageButton) findViewById(R.id.imageButtonPaste); final ImageButton ib_not = (ImageButton) findViewById(R.id.imageButtonNot); switch (todo_attachment) { case "true": ib_not.setImageResource(R.drawable.alert_circle); break; case "": ib_not.setImageResource(R.drawable.alert_circle_red); break; } ib_not.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switch (todo_attachment) { case "true": ib_not.setImageResource(R.drawable.alert_circle_red); sharedPref.edit().putString("toDo_attachment", "").apply(); todo_attachment = sharedPref.getString("toDo_attachment", ""); break; case "": ib_not.setImageResource(R.drawable.alert_circle); sharedPref.edit().putString("toDo_attachment", "true").apply(); todo_attachment = sharedPref.getString("toDo_attachment", ""); break; } } }); ib_paste.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final CharSequence[] options = { getString(R.string.paste_date), getString(R.string.paste_time) }; new android.app.AlertDialog.Builder(Activity_todo.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.paste_date))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); String dateNow = format.format(date); etNewItem.getText().insert(etNewItem.getSelectionStart(), dateNow); } if (options[item].equals(getString(R.string.paste_time))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); String timeNow = format.format(date); etNewItem.getText().insert(etNewItem.getSelectionStart(), timeNow); } } }).show(); } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String itemText = etNewItem.getText().toString(); if (itemText.isEmpty()) { Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show(); } else { itemsAdapter.add(itemText); etNewItem.setText(""); writeItems(); lvItems.post(new Runnable() { public void run() { lvItems.setSelection(lvItems.getCount() - 1); } }); } } }); }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
public void DoSettings() { // get settings.xml view LayoutInflater li = LayoutInflater.from(context); settingsView = li.inflate(R.layout.settings, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set settings.xml to alertdialog builder alertDialogBuilder.setView(settingsView); // get user input for service code final EditText userInput = (EditText) settingsView.findViewById(R.id.editTextDialogUserInput); // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override//w w w. j a v a2 s . c om public void onClick(DialogInterface dialog, int id) { SharedPreferences prefs = context.getSharedPreferences("Share", Context.MODE_PRIVATE); prefs.edit().clear(); SharedPreferences.Editor es = prefs.edit(); String[] mTestArray; if (userInput.getText().toString().equals("NoAccess")) { // prefs URL EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url); appURL = et1.getText().toString(); es.putString("com.ezac.gliderlogs.url", appURL).apply(); } // prefs PRE EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre); appPRE = et2.getText().toString().replace(" ", ""); es.putString("com.ezac.gliderlogs.pre", appPRE).apply(); if (userInput.getText().toString().equals("NoAccess")) { // prefs SCN EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn); appSCN = et3.getText().toString(); es.putString("com.ezac.gliderlogs.scn", appSCN).apply(); // prefs KEY EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key); appKEY = et4.getText().toString(); es.putString("com.ezac.gliderlogs.key", appKEY).apply(); // prefs KEY EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret); appSCT = et5.getText().toString(); es.putString("com.ezac.gliderlogs.sct", appSCT).apply(); // prefs Meteo mTestArray = getResources().getStringArray(R.array.meteo_id_arrays); Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station); String sel6 = (String) et6.getSelectedItem(); //String sel6_id = ""; for (int i = 0; i < et6.getCount(); i++) { String s1 = (String) et6.getItemAtPosition(i); if (s1.equalsIgnoreCase(sel6)) { appMST = mTestArray[i]; } } es.putString("com.ezac.gliderlogs.mst", appMST).apply(); // prefs Metar EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar); appMTR = et7.getText().toString(); es.putString("com.ezac.gliderlogs.mst", appMST).apply(); } // prefs Flags CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01); CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02); CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11); CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12); CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13); CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14); CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21); CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22); String et9aa, et9ab; String v[]; if (userInput.getText().toString().equals("To3Myd4T")) { et9aa = et9a.isChecked() ? "true" : "false"; et9ab = et9b.isChecked() ? "true" : "false"; } else { v = appFLG.split(";"); et9aa = v[0]; et9ab = v[1]; } String et9ac = et9c.isChecked() ? "true" : "false"; String et9ad = et9d.isChecked() ? "true" : "false"; String et9ae = et9e.isChecked() ? "true" : "false"; String et9af = et9f.isChecked() ? "true" : "false"; String et9ag = et9g.isChecked() ? "true" : "false"; String et9ah = et9h.isChecked() ? "true" : "false"; appFLG = et9aa + ";" + et9ab + ";" + et9ac + ";" + et9ad + ";" + et9ae + ";" + et9af + ";" + et9ag + ";" + et9ah + ";false;false"; v = appFLG.split(";"); menu.findItem(R.id.action_ezac).setVisible(Boolean.parseBoolean(v[2])); menu.findItem(R.id.action_meteo_group).setVisible(Boolean.parseBoolean(v[3])); menu.findItem(R.id.action_ntm_nld).setVisible(Boolean.parseBoolean(v[4])); menu.findItem(R.id.action_ntm_blx).setVisible(Boolean.parseBoolean(v[4])); menu.findItem(R.id.action_ogn_flarm).setVisible(Boolean.parseBoolean(v[5])); menu.findItem(R.id.action_adsb).setVisible(Boolean.parseBoolean(v[6])); menu.findItem(R.id.action_adsb_lcl).setVisible(Boolean.parseBoolean(v[7])); es.putString("com.ezac.gliderlogs.flg", appFLG).apply(); // adjust value in menu button to value in use MenuItem MenuItem_dur = menu.findItem(R.id.action_45min); MenuItem_dur.setTitle(" " + appPRE + " Min "); if (userInput.getText().toString().equals("To3Myd4T")) { // prefs airfield heading mTestArray = getResources().getStringArray(R.array.heading_arrays); Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading); String sel10 = (String) et10.getSelectedItem(); //String sel10_id = ""; for (int i = 0; i < et10.getCount(); i++) { String s2 = (String) et10.getItemAtPosition(i); if (s2.equalsIgnoreCase(sel10)) { appLND = mTestArray[i]; es.putString("com.ezac.gliderlogs.lnd", appLND).apply(); } } } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog & and load it's data AlertDialog alertDialog = alertDialogBuilder.create(); EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url); EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre); EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn); EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key); EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret); Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station); EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar); //EditText et8 = (EditText) settingsView.findViewById(R.id.setting_ntp); CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01); CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02); CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11); CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12); CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13); CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14); CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21); CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22); Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading); et1.setText(appURL); et2.setText(appPRE); et3.setText(appSCN); et4.setText(appKEY); et5.setText(appSCT); // get settings value for meteo station and set spinner String[] mTestArray; mTestArray = getResources().getStringArray(R.array.meteo_id_arrays); for (int i = 0; i < mTestArray.length; i++) { String s = mTestArray[i]; if (s.equals(appMST)) { et6.setSelection(i); } } et7.setText(appMTR); // get settings value for menu tabs and set checkboxes String v[] = appFLG.split(";"); et9a.setChecked(Boolean.parseBoolean(v[0])); et9b.setChecked(Boolean.parseBoolean(v[1])); et9c.setChecked(Boolean.parseBoolean(v[2])); et9d.setChecked(Boolean.parseBoolean(v[3])); et9e.setChecked(Boolean.parseBoolean(v[4])); et9f.setChecked(Boolean.parseBoolean(v[5])); et9g.setChecked(Boolean.parseBoolean(v[6])); et9h.setChecked(Boolean.parseBoolean(v[7])); // re-use mTestArray mTestArray = getResources().getStringArray(R.array.heading_arrays); for (int i = 0; i < mTestArray.length; i++) { String s = mTestArray[i]; if (s.equals(appLND)) { et10.setSelection(i); } } // show it alertDialog.show(); }
From source file:in.shick.diode.submit.SubmitLinkActivity.java
/** * Enable the UI after user is logged in. *//*from ww w .j ava 2 s . co m*/ private void start() { // Intents can be external (browser share page) or from Reddit is fun. String intentAction = getIntent().getAction(); if (Intent.ACTION_SEND.equals(intentAction)) { // Share Bundle extras = getIntent().getExtras(); SubmissionProperties submissionProperties = new SubmissionProperties(); boolean ignored = defaultExtractProperties(extras, submissionProperties) || lastDitchExtractProperties(extras, submissionProperties); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); submitLinkUrl.setText(submissionProperties.url); submitLinkReddit.setText(""); submitTextReddit.setText(""); submitLinkTitle.setText(submissionProperties.title); mSubmitUrl = Constants.REDDIT_BASE_URL + "/submit"; } else { String submitPath = null; Uri data = getIntent().getData(); if (data != null && Util.isRedditUri(data)) submitPath = data.getPath(); if (submitPath == null) submitPath = "/submit"; // the URL to do HTTP POST to mSubmitUrl = Util.absolutePathToURL(submitPath); // Put the subreddit in the text field final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); Matcher m = SUBMIT_PATH_PATTERN.matcher(submitPath); if (m.matches()) { String subreddit = m.group(1); if (StringUtils.isEmpty(subreddit)) { submitLinkReddit.setText(""); submitTextReddit.setText(""); } else { submitLinkReddit.setText(subreddit); submitTextReddit.setText(subreddit); } } } final Button submitLinkButton = (Button) findViewById(R.id.submit_link_button); submitLinkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateLinkForm()) { final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitLinkCaptcha = (EditText) findViewById(R.id.submit_link_captcha); new SubmitLinkTask(submitLinkTitle.getText().toString(), submitLinkUrl.getText().toString(), submitLinkReddit.getText().toString(), Constants.SUBMIT_KIND_LINK, submitLinkCaptcha.getText().toString()).execute(); } } }); final Button submitTextButton = (Button) findViewById(R.id.submit_text_button); submitTextButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateTextForm()) { final EditText submitTextTitle = (EditText) findViewById(R.id.submit_text_title); final EditText submitTextText = (EditText) findViewById(R.id.submit_text_text); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); final EditText submitTextCaptcha = (EditText) findViewById(R.id.submit_text_captcha); new SubmitLinkTask(submitTextTitle.getText().toString(), submitTextText.getText().toString(), submitTextReddit.getText().toString(), Constants.SUBMIT_KIND_SELF, submitTextCaptcha.getText().toString()).execute(); } } }); // Check the CAPTCHA new MyCaptchaCheckRequiredTask().execute(); }
From source file:cm.aptoide.pt.ManageRepos.java
private void validateRepo(final String originalUriString, final boolean editMode) { final ViewDisplayRepo originalRepo; LayoutInflater li = LayoutInflater.from(ctx); View view = li.inflate(R.layout.addrepo, null); final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg); final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2); final EditText sec_user = (EditText) view.findViewById(R.id.sec_user); final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd); final EditText uri = (EditText) view.findViewById(R.id.edit_uri); final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk); sec.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sec_user.setEnabled(true); sec_pwd.setEnabled(true); } else { sec_user.setEnabled(false); sec_pwd.setEnabled(false); }//ww w . j a v a 2 s . com } }); Builder p = new AlertDialog.Builder(theme).setView(view); alrt = p.create(); CharSequence actionButtonString; if (editMode) { originalRepo = repos.getRepo(originalUriString.hashCode()); if (originalRepo.requiresLogin()) { sec.setChecked(true); sec_user.setText(originalRepo.getLogin().getUsername()); sec_pwd.setText(originalRepo.getLogin().getPassword()); } else { sec.setChecked(false); } alrt.setIcon(R.drawable.ic_menu_edit); alrt.setTitle(getText(R.string.edit_repo)); actionButtonString = getText(R.string.edit); } else { originalRepo = null; sec.setChecked(false); alrt.setIcon(R.drawable.ic_menu_add); alrt.setTitle(getText(R.string.add_repo)); actionButtonString = getText(R.string.add); } alrt.setButton(actionButtonString, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String uriString = uri.getText().toString(); String user = null; String pwd = null; if (sec.isChecked()) { user = sec_user.getText().toString(); pwd = sec_pwd.getText().toString(); } Message msg = new Message(); uriString = uriCheck(uriString); sec_msg.setVisibility(View.GONE); sec_msg2.setVisibility(View.GONE); returnStatus result = checkServerConnection(uriString, user, pwd); switch (result) { case OK: Log.d("Aptoide-ManageRepo", "return ok"); msg.obj = 0; if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin()) ? (originalRepo.getLogin().getUsername().equals(user) && originalRepo.getLogin().getPassword().equals(pwd)) : true)) { Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show(); // finish(); } else { ViewRepository newRepo = new ViewRepository(uriString); if (isRepoManaged(uriString)) { if (user != null && pwd != null) { reposManager.removeLogin(newRepo.getHashid()); } else { newRepo.setLogin(new ViewLogin(user, pwd)); reposManager.updateLogin(newRepo); } } else { if (user != null && pwd != null) { newRepo.setLogin(new ViewLogin(user, pwd)); } if (originalUriString != null) { removeDisplayRepo(originalUriString.hashCode()); } addDisplayRepo(newRepo); refreshReposList(); } alrt.dismiss(); } break; case LOGIN_REQUIRED: Log.d("Aptoide-ManageRepo", "return login_required"); sec_msg2.setText(getText(R.string.login_required)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case BAD_LOGIN: Log.d("Aptoide-ManageRepo", "return bad_login"); sec_msg2.setText(getText(R.string.bad_login)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case FAIL: Log.d("Aptoide-ManageRepo", "return fail"); uriString = uriString.substring(0, uriString.length() - 1) + ".bazaarandroid.com/"; Log.d("Aptoide-ManageRepo", "repo uri: " + uriString); msg.obj = 1; break; default: Log.d("Aptoide-ManageRepo", "return exception"); uriString = uriString.substring(0, uriString.length() - 1) + ".bazaarandroid.com/"; Log.d("Aptoide-ManageRepo", "repo uri: " + uriString); msg.obj = 1; break; } if (result.equals(returnStatus.FAIL) || result.equals(returnStatus.EXCEPTION)) { returnStatus result2 = checkServerConnection(uriString, user, pwd); switch (result2) { case OK: Log.d("Aptoide-ManageRepo", "return ok"); msg.obj = 0; if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin()) ? (originalRepo.getLogin().getUsername().equals(user) && originalRepo.getLogin().getPassword().equals(pwd)) : true)) { Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show(); // finish(); } else { ViewRepository newRepo = new ViewRepository(uriString); if (isRepoManaged(uriString)) { if (user != null && pwd != null) { reposManager.removeLogin(newRepo.getHashid()); } else { newRepo.setLogin(new ViewLogin(user, pwd)); reposManager.updateLogin(newRepo); } } else { if (user != null && pwd != null) { newRepo.setLogin(new ViewLogin(user, pwd)); } if (originalUriString != null) { removeDisplayRepo(originalUriString.hashCode()); } addDisplayRepo(newRepo); refreshReposList(); } alrt.dismiss(); } break; case LOGIN_REQUIRED: Log.d("Aptoide-ManageRepo", "return login_required"); sec_msg2.setText(getText(R.string.login_required)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case BAD_LOGIN: Log.d("Aptoide-ManageRepo", "return bad_login"); sec_msg2.setText(getText(R.string.bad_login)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case FAIL: Log.d("Aptoide-ManageRepo", "return fail"); sec_msg.setText(getText(R.string.cant_connect)); sec_msg.setVisibility(View.VISIBLE); msg.obj = 1; break; default: Log.d("Aptoide-ManageRepo", "return exception"); msg.obj = 1; break; } } invalidRepo.sendMessage(msg); } }); alrt.setButton2(getText(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alrt.dismiss(); } }); alrt.show(); if (originalUriString != null) { uri.setText(originalUriString); } }
From source file:pt.aptoide.backupapps.ManageRepos.java
private void validateRepo(final String originalUriString, final boolean editMode) { final ViewDisplayRepo originalRepo; LayoutInflater li = LayoutInflater.from(ctx); View view = li.inflate(R.layout.addrepo, null); final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg); final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2); final EditText sec_user = (EditText) view.findViewById(R.id.sec_user); final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd); final EditText uri = (EditText) view.findViewById(R.id.edit_uri); final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk); sec.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sec_user.setEnabled(true); sec_pwd.setEnabled(true); } else { sec_user.setEnabled(false); sec_pwd.setEnabled(false); }/*from w w w . ja v a 2s . com*/ } }); Builder p = new AlertDialog.Builder(theme).setView(view); alrt = p.create(); CharSequence actionButtonString; if (editMode) { originalRepo = repos.getRepo(originalUriString.hashCode()); if (originalRepo.requiresLogin()) { sec.setChecked(true); sec_user.setText(originalRepo.getLogin().getUsername()); sec_pwd.setText(originalRepo.getLogin().getPassword()); } else { sec.setChecked(false); } alrt.setIcon(R.drawable.ic_menu_edit); alrt.setTitle(getText(R.string.edit_repo)); actionButtonString = getText(R.string.edit); } else { originalRepo = null; sec.setChecked(false); alrt.setIcon(R.drawable.ic_menu_add); alrt.setTitle(getText(R.string.add_repo)); actionButtonString = getText(R.string.add); } alrt.setButton(actionButtonString, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String uriString = uri.getText().toString(); String user = null; String pwd = null; if (sec.isChecked()) { user = sec_user.getText().toString(); pwd = sec_pwd.getText().toString(); } Message msg = new Message(); uriString = uriCheck(uriString); sec_msg.setVisibility(View.GONE); sec_msg2.setVisibility(View.GONE); returnStatus result = checkServerConnection(uriString, user, pwd); switch (result) { case OK: Log.d("Aptoide-ManageRepo", "return ok"); msg.obj = 0; if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin()) ? (originalRepo.getLogin().getUsername().equals(user) && originalRepo.getLogin().getPassword().equals(pwd)) : true)) { Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show(); // finish(); } else { ViewRepository newRepo = new ViewRepository(uriString); if (isRepoManaged(uriString)) { if (user != null && pwd != null) { reposManager.removeLogin(newRepo.getHashid()); } else { newRepo.setLogin(new ViewLogin(user, pwd)); reposManager.updateLogin(newRepo); } } else { if (user != null && pwd != null) { newRepo.setLogin(new ViewLogin(user, pwd)); } if (originalUriString != null) { removeDisplayRepo(originalUriString.hashCode()); } addDisplayRepo(newRepo); refreshReposList(); } alrt.dismiss(); } break; case LOGIN_REQUIRED: Log.d("Aptoide-ManageRepo", "return login_required"); sec_msg2.setText(getText(R.string.login_required)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case BAD_LOGIN: Log.d("Aptoide-ManageRepo", "return bad_login"); sec_msg2.setText(getText(R.string.check_login)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case FAIL: Log.d("Aptoide-ManageRepo", "return fail"); uriString = uriString.substring(0, uriString.length() - 1) + Constants.DOMAIN_APTOIDE_STORE; Log.d("Aptoide-ManageRepo", "repo uri: " + uriString); msg.obj = 1; break; default: Log.d("Aptoide-ManageRepo", "return exception"); uriString = uriString.substring(0, uriString.length() - 1) + Constants.DOMAIN_APTOIDE_STORE; Log.d("Aptoide-ManageRepo", "repo uri: " + uriString); msg.obj = 1; break; } if (result.equals(returnStatus.FAIL) || result.equals(returnStatus.EXCEPTION)) { returnStatus result2 = checkServerConnection(uriString, user, pwd); switch (result2) { case OK: Log.d("Aptoide-ManageRepo", "return ok"); msg.obj = 0; if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin()) ? (originalRepo.getLogin().getUsername().equals(user) && originalRepo.getLogin().getPassword().equals(pwd)) : true)) { Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show(); // finish(); } else { ViewRepository newRepo = new ViewRepository(uriString); if (isRepoManaged(uriString)) { if (user != null && pwd != null) { reposManager.removeLogin(newRepo.getHashid()); } else { newRepo.setLogin(new ViewLogin(user, pwd)); reposManager.updateLogin(newRepo); } } else { if (user != null && pwd != null) { newRepo.setLogin(new ViewLogin(user, pwd)); } if (originalUriString != null) { removeDisplayRepo(originalUriString.hashCode()); } addDisplayRepo(newRepo); refreshReposList(); } alrt.dismiss(); } break; case LOGIN_REQUIRED: Log.d("Aptoide-ManageRepo", "return login_required"); sec_msg2.setText(getText(R.string.login_required)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case BAD_LOGIN: Log.d("Aptoide-ManageRepo", "return bad_login"); sec_msg2.setText(getText(R.string.check_login)); sec_msg2.setVisibility(View.VISIBLE); msg.obj = 1; break; case FAIL: Log.d("Aptoide-ManageRepo", "return fail"); sec_msg.setText(getText(R.string.cant_connect)); sec_msg.setVisibility(View.VISIBLE); msg.obj = 1; break; default: Log.d("Aptoide-ManageRepo", "return exception"); msg.obj = 1; break; } } invalidRepo.sendMessage(msg); } }); alrt.setButton2(getText(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alrt.dismiss(); } }); alrt.show(); if (originalUriString != null) { uri.setText(originalUriString); } }
From source file:com.irccloud.android.activity.UploadsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (ColorFormatter.file_uri_template != null) template = UriTemplate.fromTemplate(ColorFormatter.file_uri_template); super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC));/*from w ww . j av a 2 s.c o m*/ cloud.recycle(); } if (Build.VERSION.SDK_INT >= 14) { try { java.io.File httpCacheDir = new java.io.File(getCacheDir(), "http"); long httpCacheSize = 10 * 1024 * 1024; // 10 MiB HttpResponseCache.install(httpCacheDir, httpCacheSize); } catch (IOException e) { Log.i("IRCCloud", "HTTP response cache installation failed:" + e); } } setContentView(R.layout.ignorelist); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha); getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar)); getSupportActionBar().setElevation(0); } if (savedInstanceState != null && savedInstanceState.containsKey("cid")) { cid = savedInstanceState.getInt("cid"); to = savedInstanceState.getString("to"); msg = savedInstanceState.getString("msg"); page = savedInstanceState.getInt("page"); File[] files = (File[]) savedInstanceState.getSerializable("adapter"); for (File f : files) { adapter.addFile(f); } adapter.notifyDataSetChanged(); } footer = getLayoutInflater().inflate(R.layout.messageview_header, null); ListView listView = (ListView) findViewById(android.R.id.list); listView.setAdapter(adapter); listView.addFooterView(footer); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) { canLoadMore = false; new FetchFilesTask().execute((Void) null); } } }); listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { final File f = (File) adapter.getItem(i); AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); final View v = getLayoutInflater().inflate(R.layout.dialog_upload, null); final EditText messageinput = (EditText) v.findViewById(R.id.message); messageinput.setText(msg); final ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail); v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (messageinput.hasFocus()) { v.post(new Runnable() { @Override public void run() { v.scrollTo(0, v.getBottom()); } }); } } }); if (f.mime_type.startsWith("image/")) { try { thumbnail.setImageBitmap(f.image); thumbnail.setVisibility(View.VISIBLE); thumbnail.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(UploadsActivity.this, ImageViewerActivity.class); i.setData(Uri.parse(f.url)); startActivity(i); } }); thumbnail.setClickable(true); } catch (Exception e) { e.printStackTrace(); } } else { thumbnail.setVisibility(View.GONE); } ((TextView) v.findViewById(R.id.filesize)).setText(f.metadata); v.findViewById(R.id.filename).setVisibility(View.GONE); v.findViewById(R.id.filename_heading).setVisibility(View.GONE); builder.setTitle("Send A File To " + to); builder.setView(v); builder.setPositiveButton("Send", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String message = messageinput.getText().toString(); if (message.length() > 0) message += " "; message += f.url; dialog.dismiss(); if (getParent() == null) { setResult(Activity.RESULT_OK); } else { getParent().setResult(Activity.RESULT_OK); } finish(); NetworkConnection.getInstance().say(cid, to, message); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog d = builder.create(); d.setOwnerActivity(UploadsActivity.this); d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); d.show(); } }); }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); final SharedPreferences settings = activity.getApiCall().settings; sort = settings.getString("CommentSort", "Best"); boolean newData = true; if (commentData != null) { newData = false;/*from w w w. j a v a 2 s. co m*/ } mainView = inflater.inflate(R.layout.single_image_layout, container, false); String[] mMenuList = getResources().getStringArray(R.array.emptyList); if (commentAdapter == null) commentAdapter = new CommentAdapter(mainView.getContext()); commentLayout = (ListView) mainView.findViewById(R.id.comment_thread); commentLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE); if (settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT)) imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.image_view, null); else imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.dark_image_view, null); mPullToRefreshLayout = (PullToRefreshLayout) mainView.findViewById(R.id.ptr_layout); ActionBarPullToRefresh.from(getActivity()) // Mark All Children as pullable .allChildrenArePullable() // Set the OnRefreshListener .listener(this) // Finally commit the setup to our PullToRefreshLayout .setup(mPullToRefreshLayout); if (savedInstanceState != null && newData) { imageData = savedInstanceState.getParcelable("imageData"); inGallery = savedInstanceState.getBoolean("inGallery"); } LinearLayout layout = (LinearLayout) imageLayoutView.findViewById(R.id.image_buttons); TextView imageDetails = (TextView) imageLayoutView.findViewById(R.id.single_image_details); layout.setVisibility(View.VISIBLE); ImageButton imageFullscreen = (ImageButton) imageLayoutView.findViewById(R.id.fullscreen); imageUpvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_good); imageDownvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_bad); ImageButton imageFavorite = (ImageButton) imageLayoutView.findViewById(R.id.rating_favorite); imageComment = (ImageButton) imageLayoutView.findViewById(R.id.comment); ImageButton imageUser = (ImageButton) imageLayoutView.findViewById(R.id.user); imageScore = (TextView) imageLayoutView.findViewById(R.id.single_image_score); TextView imageInfo = (TextView) imageLayoutView.findViewById(R.id.single_image_info); Log.d("imageData", imageData.getJSONObject().toString()); if (imageData.getJSONObject().has("ups")) { imageUpvote.setVisibility(View.VISIBLE); imageDownvote.setVisibility(View.VISIBLE); imageScore.setVisibility(View.VISIBLE); imageComment.setVisibility(View.VISIBLE); ImageUtils.updateImageFont(imageData, imageScore); } imageInfo.setVisibility(View.VISIBLE); ImageUtils.updateInfoFont(imageData, imageInfo); imageUser.setVisibility(View.VISIBLE); imageFavorite.setVisibility(View.VISIBLE); try { if (!imageData.getJSONObject().has("account_url") || imageData.getJSONObject().getString("account_url").equals("null") || imageData.getJSONObject().getString("account_url").equals("[deleted]")) imageUser.setVisibility(View.GONE); if (!imageData.getJSONObject().has("vote")) { imageUpvote.setVisibility(View.GONE); imageDownvote.setVisibility(View.GONE); } else { if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("up")) imageUpvote.setImageResource(R.drawable.green_rating_good); else if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("down")) imageDownvote.setImageResource(R.drawable.red_rating_bad); } if (imageData.getJSONObject().getString("favorite") != null && imageData.getJSONObject().getBoolean("favorite")) imageFavorite.setImageResource(R.drawable.green_rating_favorite); } catch (JSONException e) { Log.e("Error!", e.toString()); } imageFavorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.favoriteImage(singleImageFragment, imageData, (ImageButton) view, activity.getApiCall()); } }); imageUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.gotoUser(singleImageFragment, imageData); } }); imageComment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Activity activity = getActivity(); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_body); newBody.setLines(3); final TextView characterCount = new TextView(activity); characterCount.setText("140"); LinearLayout commentReplyLayout = new LinearLayout(activity); newBody.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { // } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { characterCount.setText(String.valueOf(140 - charSequence.length())); } @Override public void afterTextChanged(Editable editable) { for (int i = editable.length(); i > 0; i--) { if (editable.subSequence(i - 1, i).toString().equals("\n")) editable.replace(i - 1, i, ""); } } }); commentReplyLayout.setOrientation(LinearLayout.VERTICAL); commentReplyLayout.addView(newBody); commentReplyLayout.addView(characterCount); new AlertDialog.Builder(activity).setTitle(R.string.dialog_comment_on_image_title) .setView(commentReplyLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newBody.getText() != null && newBody.getText().toString().length() < 141) { HashMap<String, Object> commentMap = new HashMap<String, Object>(); try { commentMap.put("comment", newBody.getText().toString()); commentMap.put("image_id", imageData.getJSONObject().getString("id")); Fetcher fetcher = new Fetcher(singleImageFragment, "3/comment/", ApiCall.POST, commentMap, ((ImgurHoloActivity) getActivity()).getApiCall(), POSTCOMMENT); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } }); imageUpvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.upVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); imageDownvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.downVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); if (popupWindow != null) { popupWindow.dismiss(); } popupWindow = new PopupWindow(); imageFullscreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.fullscreen(singleImageFragment, imageData, popupWindow, mainView); } }); ArrayAdapter<String> tempAdapter = new ArrayAdapter<String>(mainView.getContext(), R.layout.drawer_list_item, mMenuList); Log.d("URI", "YO I'M IN YOUR SINGLE FRAGMENT gallery:" + inGallery); imageView = (ImageView) imageLayoutView.findViewById(R.id.single_image_view); loadImage(); TextView imageTitle = (TextView) imageLayoutView.findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView.findViewById(R.id.single_image_description); try { String size = String .valueOf(NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_WIDTH))) + "x" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_HEIGHT)) + " (" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_SIZE)) + "B)"; String initial = imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) + " " + Html.fromHtml("•") + " " + size + " " + Html.fromHtml("•") + " " + "Views: " + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_VIEWS)); imageDetails.setText(initial); Log.d("imagedata", imageData.getJSONObject().toString()); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) imageTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); else imageTitle.setVisibility(View.GONE); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) { imageDescription .setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); commentLayout.addHeaderView(imageLayoutView); commentLayout.setAdapter(tempAdapter); } catch (JSONException e) { Log.e("Text Error!", e.toString()); } if ((savedInstanceState == null || commentData == null) && newData) { commentData = new JSONParcelable(); getComments(); commentLayout.setAdapter(commentAdapter); } else if (newData) { commentArray = savedInstanceState.getParcelableArrayList("commentData"); commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } else if (commentArray != null) { commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } return mainView; }