List of usage examples for android.widget TextView setVisibility
@RemotableViewMethod public void setVisibility(@Visibility int visibility)
From source file:com.android.soma.Launcher.java
public void showFirstRunCling() { if (isClingsEnabled() && !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) && !skipCustomClingIfNoAccounts()) { // If we're not using the default workspace layout, replace workspace cling // with a custom workspace cling (usually specified in an overlay) // For now, only do this on tablets if (!DISABLE_CUSTOM_CLINGS) { if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 && getResources().getBoolean(R.bool.config_useCustomClings)) { // Use a custom cling View cling = findViewById(R.id.workspace_cling); ViewGroup clingParent = (ViewGroup) cling.getParent(); int clingIndex = clingParent.indexOfChild(cling); clingParent.removeViewAt(clingIndex); View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false); clingParent.addView(customCling, clingIndex); customCling.setId(R.id.workspace_cling); }/*from ww w. j av a 2s .c om*/ } Cling cling = (Cling) findViewById(R.id.first_run_cling); if (cling != null) { String sbHintStr = getFirstRunClingSearchBarHint(); String ccHintStr = getFirstRunCustomContentHint(); if (!sbHintStr.isEmpty()) { TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint); sbHint.setText(sbHintStr); sbHint.setVisibility(View.VISIBLE); } setCustomContentHintVisibility(cling, ccHintStr, true, false); } initCling(R.id.first_run_cling, 0, false, true); } else { removeCling(R.id.first_run_cling); } }
From source file:com.android.soma.Launcher.java
private void setCustomContentHintVisibility(Cling cling, String ccHintStr, boolean visible, boolean animate) { final TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint); if (ccHint != null) { if (visible && !ccHintStr.isEmpty()) { ccHint.setText(ccHintStr);/*from ww w.j a v a 2 s . co m*/ ccHint.setVisibility(View.VISIBLE); if (animate) { ccHint.setAlpha(0f); ccHint.animate().alpha(1f).setDuration(SHOW_CLING_DURATION).start(); } else { ccHint.setAlpha(1f); } } else { if (animate) { ccHint.animate().alpha(0f).setDuration(SHOW_CLING_DURATION) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { ccHint.setVisibility(View.GONE); } }).start(); } else { ccHint.setAlpha(0f); ccHint.setVisibility(View.GONE); } } } }
From source file:com.irccloud.android.activity.MainActivity.java
void editTopic() { ChannelsDataSource.Channel c = ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); View view = getDialogTextPrompt(); TextView prompt = (TextView) view.findViewById(R.id.prompt); final EditText input = (EditText) view.findViewById(R.id.textInput); input.setText(c.topic_text);/*from w w w. ja va2 s. c om*/ prompt.setVisibility(View.GONE); builder.setTitle("Channel Topic"); builder.setView(view); builder.setPositiveButton("Set Topic", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { conn.topic(buffer.cid, buffer.name, input.getText().toString()); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.setOwnerActivity(this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); }
From source file:com.amaze.carbonfilemanager.activities.MainActivity.java
public void updatePath(@NonNull final String news, boolean results, OpenMode openmode, int folder_count, int file_count) { if (news.length() == 0) return;/*from w w w. ja va2 s .co m*/ switch (openmode) { case SMB: newPath = mainActivityHelper.parseSmbPath(news); break; case OTG: newPath = mainActivityHelper.parseOTGPath(news); break; case CUSTOM: newPath = mainActivityHelper.getIntegralNames(news); break; case DROPBOX: case BOX: case ONEDRIVE: case GDRIVE: newPath = mainActivityHelper.parseCloudPath(openmode, news); break; default: newPath = news; } final TextView bapath = (TextView) pathbar.findViewById(R.id.fullpath); final TextView animPath = (TextView) pathbar.findViewById(R.id.fullpath_anim); TextView textView = (TextView) pathbar.findViewById(R.id.pathname); if (!results) { textView.setText(folder_count + " " + getResources().getString(R.string.folders) + "" + " " + file_count + " " + getResources().getString(R.string.files)); } else { bapath.setText(R.string.searchresults); textView.setText(R.string.empty); return; } final String oldPath = bapath.getText().toString(); if (oldPath.equals(newPath)) return; // implement animation while setting text newPathBuilder = new StringBuffer().append(newPath); oldPathBuilder = new StringBuffer().append(oldPath); final Animation slideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in); Animation slideOut = AnimationUtils.loadAnimation(this, R.anim.slide_out); if (newPath.length() > oldPath.length() && newPathBuilder.delete(oldPath.length(), newPath.length()).toString().equals(oldPath) && oldPath.length() != 0) { // navigate forward newPathBuilder.delete(0, newPathBuilder.length()); newPathBuilder.append(newPath); newPathBuilder.delete(0, oldPath.length()); animPath.setAnimation(slideIn); animPath.animate().setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); new Handler().postDelayed(new Runnable() { @Override public void run() { animPath.setVisibility(View.GONE); bapath.setText(newPath); } }, PATH_ANIM_END_DELAY); } @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); animPath.setVisibility(View.VISIBLE); animPath.setText(newPathBuilder.toString()); //bapath.setText(oldPath); scroll.post(new Runnable() { @Override public void run() { scroll1.fullScroll(View.FOCUS_RIGHT); } }); } @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); //onAnimationEnd(animation); } }).setStartDelay(PATH_ANIM_START_DELAY).start(); } else if (newPath.length() < oldPath.length() && oldPathBuilder.delete(newPath.length(), oldPath.length()).toString().equals(newPath)) { // navigate backwards oldPathBuilder.delete(0, oldPathBuilder.length()); oldPathBuilder.append(oldPath); oldPathBuilder.delete(0, newPath.length()); animPath.setAnimation(slideOut); animPath.animate().setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); animPath.setVisibility(View.GONE); bapath.setText(newPath); scroll.post(new Runnable() { @Override public void run() { scroll1.fullScroll(View.FOCUS_RIGHT); } }); } @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); animPath.setVisibility(View.VISIBLE); animPath.setText(oldPathBuilder.toString()); bapath.setText(newPath); scroll.post(new Runnable() { @Override public void run() { scroll1.fullScroll(View.FOCUS_LEFT); } }); } }).setStartDelay(PATH_ANIM_START_DELAY).start(); } else if (oldPath.isEmpty()) { // case when app starts // FIXME: COUNTER is incremented twice on app startup COUNTER++; if (COUNTER == 2) { animPath.setAnimation(slideIn); animPath.setText(newPath); animPath.animate().setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); animPath.setVisibility(View.VISIBLE); bapath.setText(""); scroll.post(new Runnable() { @Override public void run() { scroll1.fullScroll(View.FOCUS_RIGHT); } }); } @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); new Handler().postDelayed(new Runnable() { @Override public void run() { animPath.setVisibility(View.GONE); bapath.setText(newPath); } }, PATH_ANIM_END_DELAY); } @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); //onAnimationEnd(animation); } }).setStartDelay(PATH_ANIM_START_DELAY).start(); } } else { // completely different path // first slide out of old path followed by slide in of new path animPath.setAnimation(slideOut); animPath.animate().setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animator) { super.onAnimationStart(animator); animPath.setVisibility(View.VISIBLE); animPath.setText(oldPath); bapath.setText(""); scroll.post(new Runnable() { @Override public void run() { scroll1.fullScroll(View.FOCUS_LEFT); } }); } @Override public void onAnimationEnd(Animator animator) { super.onAnimationEnd(animator); //animPath.setVisibility(View.GONE); animPath.setText(newPath); bapath.setText(""); animPath.setAnimation(slideIn); animPath.animate().setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); new Handler().postDelayed(new Runnable() { @Override public void run() { animPath.setVisibility(View.GONE); bapath.setText(newPath); } }, PATH_ANIM_END_DELAY); } @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); // we should not be having anything here in path bar animPath.setVisibility(View.VISIBLE); bapath.setText(""); scroll.post(new Runnable() { @Override public void run() { scroll1.fullScroll(View.FOCUS_RIGHT); } }); } }).start(); } @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); //onAnimationEnd(animation); } }).setStartDelay(PATH_ANIM_START_DELAY).start(); } }
From source file:com.markupartist.sthlmtraveling.PlannerFragment.java
public void initViews() { mSearchView = getActivity().getLayoutInflater().inflate(R.layout.search, null); getListView().addHeaderView(mSearchView, null, false); final TextView historyView = (TextView) getActivity().getLayoutInflater().inflate(R.layout.header, null); historyView.setText(R.string.history_label); historyView.setOnClickListener(null); // Makes the header un-clickable, hack! getListView().addHeaderView(historyView); // Hide dividers on the header view. getListView().setHeaderDividersEnabled(false); if (!mStartPoint.hasName()) { mStartPoint.setName(Site.TYPE_MY_LOCATION); }// w w w. j a v a 2 s .co m mStartPointAutoComplete = createAutoCompleteTextView(R.id.from, /*R.id.from_progress*/ -1, mStartPoint); mEndPointAutoComplete = createAutoCompleteTextView(R.id.to, /*R.id.to_progress*/ -1, mEndPoint); mViaPointAutoComplete = createAutoCompleteTextView(R.id.via, /*R.id.via_progress*/ -1, mViaPoint, true); try { mHistoryDbAdapter = new HistoryDbAdapter(getActivity()).open(); } catch (final Exception e) { showDialog(createDialogReinstallApp()); return; } // Setup view for choosing other data for start and end point. final ImageButton fromDialog = (ImageButton) mSearchView.findViewById(R.id.from_menu); fromDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mStartPointAutoComplete.setError(null); showDialog(createDialogStartPoint()); } }); final ImageButton toDialog = (ImageButton) mSearchView.findViewById(R.id.to_menu); toDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mEndPointAutoComplete.setError(null); showDialog(createDialogEndPoint()); } }); final ImageButton viaDialog = (ImageButton) mSearchView.findViewById(R.id.via_menu); viaDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mViaPointAutoComplete.setError(null); showDialog(createDialogViaPoint()); } }); // Views for date and time mChangeTimeLayout = (LinearLayout) mSearchView.findViewById(R.id.planner_change_time_layout); mDateButton = (Button) mSearchView.findViewById(R.id.planner_route_date); mDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { showDialog(createDialogDate()); } }); mTimeButton = (Button) mSearchView.findViewById(R.id.planner_route_time); mTimeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { showDialog(createDialogTime()); } }); // Views for radio buttons final RadioButton nowRadioButton = (RadioButton) mSearchView.findViewById(R.id.planner_check_now); nowRadioButton.setOnCheckedChangeListener(this); final RadioButton laterRadioButton = (RadioButton) mSearchView .findViewById(R.id.planner_check_more_choices); laterRadioButton.setOnCheckedChangeListener(this); mWhenSpinner = (Spinner) mSearchView.findViewById(R.id.departure_arrival_choice); final ArrayAdapter<CharSequence> whenChoiceAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.when_choice, android.R.layout.simple_spinner_item); whenChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWhenSpinner.setAdapter(whenChoiceAdapter); // Handle create shortcut. if (mCreateShortcut) { registerScreen("Planner create shortcut"); getActivity().setTitle(R.string.create_shortcut_label); // Add search label to button RadioGroup chooseTimeGroup = (RadioGroup) mSearchView.findViewById(R.id.planner_choose_time_group); chooseTimeGroup.setVisibility(View.GONE); historyView.setVisibility(View.GONE); // Fake an adapter. This needs to be fixed later on so we can use the history. setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.journey_history_row)); } else { setListAdapter(mAdapter); } }
From source file:com.nest5.businessClient.Initialactivity.java
@Override public void OnOrderFomrFragmentCreatedListener(View v) { Spinner addToOpenTable = (Spinner) v.findViewById(R.id.open_tables_add_order); TextView title = (TextView) v.findViewById(R.id.add_toopentable_title); if (openTables.size() > 0) { title.setVisibility(View.VISIBLE); addToOpenTable.setVisibility(View.VISIBLE); ArrayList<String> nameTables = new ArrayList<String>(); nameTables.add("No, es una mesa nueva."); for (CurrentTable<Table, Integer> current : openTables) { nameTables.add(current.getTable().getName()); }/*www . j av a2s. c o m*/ ArrayAdapter<String> adapter = new ArrayAdapter<String>(Initialactivity.this, android.R.layout.simple_spinner_item, nameTables); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); addToOpenTable.setAdapter(adapter); addToOpenTable.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { int pos = position - 1; currentSelectedAddTable = pos; if (pos > -1) currentTable = openTables.get(pos); } @Override public void onNothingSelected(AdapterView<?> arg0) { //currentSelectedAddTable = -1; } }); } else { title.setVisibility(View.INVISIBLE); addToOpenTable.setVisibility(View.INVISIBLE); } }
From source file:com.ichi2.anki.Info.java
@Override protected void onCreate(Bundle savedInstanceState) { Timber.d("onCreate()"); Themes.applyTheme(this); super.onCreate(savedInstanceState); Resources res = getResources(); mType = getIntent().getIntExtra(TYPE_EXTRA, TYPE_ABOUT); setTitle(getTitleString());/* w w w . j a v a 2 s . co m*/ setContentView(R.layout.info); mWebView = (WebView) findViewById(R.id.info); mWebView.setBackgroundColor(res.getColor(Themes.getBackgroundColor())); Themes.setWallpaper((View) mWebView.getParent().getParent().getParent()); TextView termsAndConditionsView = (TextView) findViewById(R.id.info_terms_and_conditions); termsAndConditionsView.setMovementMethod(LinkMovementMethod.getInstance()); Button continueButton = (Button) findViewById(R.id.info_continue); continueButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (mType == TYPE_ABOUT) { if (AnkiDroidApp.isKindle()) { Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.amazon.com/gp/mas/dl/android?p=com.ichi2.anki")); startActivity(intent); } else { Info.this.startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.ichi2.anki"))); } return; } setResult(RESULT_OK); switch (mType) { case TYPE_NEW_VERSION: AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit() .putString("lastVersion", AnkiDroidApp.getPkgVersionName()).commit(); break; case TYPE_UPGRADE_DECKS: break; } finishWithAnimation(); } }); StringBuilder sb = new StringBuilder(); switch (mType) { case TYPE_ABOUT: String[] content = res.getStringArray(R.array.about_content); sb.append("<html><body text=\"#000000\" link=\"#E37068\" alink=\"#E37068\" vlink=\"#E37068\">"); sb.append( String.format(content[0], res.getString(R.string.app_name), res.getString(R.string.link_anki))) .append("<br/><br/>"); sb.append(String.format(content[1], res.getString(R.string.link_issue_tracker), res.getString(R.string.link_wiki), res.getString(R.string.link_forum))).append("<br/><br/>"); sb.append(String.format(content[2], res.getString(R.string.link_wikipedia_open_source), res.getString(R.string.link_contribution), res.getString(R.string.link_contribution_contributors))).append(" "); sb.append(String.format(content[3], res.getString(R.string.link_translation), res.getString(R.string.link_donation))).append("<br/><br/>"); sb.append(String.format(content[4], res.getString(R.string.licence_wiki), res.getString(R.string.link_source))).append("<br/><br/>"); sb.append("</body></html>"); mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null); ((Button) findViewById(R.id.info_continue)).setText(res.getString(R.string.info_rate)); Button debugCopy = ((Button) findViewById(R.id.info_later)); debugCopy.setText(res.getString(R.string.feedback_copy_debug)); debugCopy.setVisibility(View.VISIBLE); debugCopy.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { copyDebugInfo(); } }); break; case TYPE_NEW_VERSION: sb.append(res.getString(R.string.new_version_message)); sb.append("<ul>"); String[] features = res.getStringArray(R.array.new_version_features); for (int i = 0; i < features.length; i++) { sb.append("<li>"); sb.append(features[i]); sb.append("</li>"); } sb.append("</ul>"); sb.append( "<br><br><br>A new design is coming in v2.5, <a href=\"https://groups.google.com/d/msg/anki-android/DrMPHn9NQtk/aZYXdIZRCwAJ\">preview it here</a>!"); sb.append("</body></html>"); mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null); // reactivating ssl check for every new version AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit().putBoolean("sslAcceptAll", false) .commit(); break; case TYPE_SHARED_DECKS: mLoadingLayer = (RelativeLayout) findViewById(R.id.info_loading_layer); mLoadingLayer.setVisibility(View.VISIBLE); try { mShareDecksTemplate = Utils.convertStreamToString(getAssets().open("shared_decks_template.html")); } catch (IOException e) { e.printStackTrace(); } mWebView.setWebViewClient(new MobileAnkiWebview()); mWebView.loadUrl(res.getString(R.string.shared_decks_url)); mWebView.getSettings().setJavaScriptEnabled(true); termsAndConditionsView.setVisibility(View.VISIBLE); continueButton.setText(res.getString(R.string.download_button_return)); break; case TYPE_UPGRADE_DECKS: setTitle(R.string.deck_upgrade_title); sb.append("<html><body>"); // add "later" button Button but = (Button) findViewById(R.id.info_later); but.setVisibility(View.VISIBLE); // add sync button Button syncButton = (Button) findViewById(R.id.info_sync); syncButton.setVisibility(View.VISIBLE); mUpgradeStage = getIntent().getIntExtra(TYPE_UPGRADE_STAGE, -1); boolean reupgrading = false; switch (mUpgradeStage) { case UPGRADE_SCREEN_BASIC1: sb.append(getString(R.string.deck_upgrade_major_warning)); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Themes.showThemedToast(Info.this, getString(R.string.deck_upgrade_start_again_to_upgrade_toast), false); setResult(RESULT_CANCELED); finish(); } }); syncButton.setText(R.string.more_options); syncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_MORE_OPTIONS); setResult(RESULT_OK, result); finishWithAnimation(); } }); continueButton.setText(R.string.now); continueButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2); setResult(RESULT_OK, result); finishWithAnimation(); } }); break; case UPGRADE_SCREEN_BASIC2: sb.append(getString(R.string.deck_upgrade_recommended_method)); but.setText(R.string.back); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1); result.putExtra(TYPE_ANIMATION_RIGHT, true); setResult(RESULT_OK, result); finishWithAnimation(false); } }); syncButton.setEnabled(false); syncButton.setText("N/A"); syncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_WEB_UPGRADE); setResult(RESULT_OK, result); finishWithAnimation(); } }); continueButton.setText(getString(R.string.pc)); continueButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_PC_UPGRADE); setResult(RESULT_OK, result); finishWithAnimation(); } }); break; case UPGRADE_SCREEN_MORE_OPTIONS: // If re-upgrading a collection exists already, so don't offer to make a new one if (new File(AnkiDroidApp.getCollectionPath()).exists()) { setTitle(getString(R.string.exit_wizard)); reupgrading = true; sb.append(getString(R.string.deck_upgrade_more_options_exit)); } else { sb.append(getString(R.string.deck_upgrade_more_options_new_collection)); } sb.append(getString(R.string.deck_upgrade_more_options_downgrade)); but.setText(R.string.upgrade_decks_button); but.setText(R.string.back); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1); result.putExtra(TYPE_ANIMATION_RIGHT, true); setResult(RESULT_OK, result); finishWithAnimation(false); } }); if (reupgrading) { syncButton.setText(getString(R.string.upgrade_deck_dont_upgrade)); syncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_CONTINUE); setResult(RESULT_OK, result); finishWithAnimation(); } }); } else { syncButton.setText(R.string.deck_upgrade_create_new_collection_button); syncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { StyledDialog.Builder builder = new StyledDialog.Builder(Info.this); builder.setTitle(R.string.deck_upgrade_create_new_collection_title); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(R.string.deck_upgrade_not_import_warning); builder.setPositiveButton(R.string.dialog_positive_create, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_CONTINUE); setResult(RESULT_OK, result); finishWithAnimation(); } }); builder.setNegativeButton(R.string.dialog_cancel, null); builder.show(); } }); } continueButton.setVisibility(View.GONE); break; case UPGRADE_SCREEN_WEB_UPGRADE: sb.append(getString(R.string.deck_upgrade_via_web)); but.setText(R.string.back); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2); result.putExtra(TYPE_ANIMATION_RIGHT, true); setResult(RESULT_OK, result); finishWithAnimation(false); } }); syncButton.setVisibility(View.GONE); continueButton.setText(R.string.dialog_continue); continueButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { lockScreenOrientation(); Connection.upgradeDecks(mWebUpgradeListener, new Connection.Payload( new Object[] { AnkiDroidApp.getCurrentAnkiDroidDirectory() })); } }); break; case UPGRADE_SCREEN_PC_UPGRADE: sb.append(getString(R.string.deck_upgrade_via_anki_desktop)); but.setText(R.string.back); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2); result.putExtra(TYPE_ANIMATION_RIGHT, true); setResult(RESULT_OK, result); finishWithAnimation(false); } }); syncButton.setText(R.string.usb); syncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_MANUAL_UPGRADE); setResult(RESULT_OK, result); finishWithAnimation(); } }); continueButton.setEnabled(false); continueButton.setText("N/A"); continueButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_AUTO_UPGRADE); setResult(RESULT_OK, result); finishWithAnimation(); } }); break; case UPGRADE_SCREEN_MANUAL_UPGRADE: sb.append(getString(R.string.deck_upgrade_manual)); but.setText(R.string.back); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2); result.putExtra(TYPE_ANIMATION_RIGHT, true); setResult(RESULT_OK, result); finishWithAnimation(false); } }); syncButton.setText(R.string._import); syncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { File apkgFile = new File(AnkiDroidApp.getCurrentAnkiDroidDirectory(), DeckPicker.IMPORT_REPLACE_COLLECTION_NAME); List<File> importables = Utils.getImportableDecks(); if (importables == null || !importables.contains(apkgFile)) { Themes.showThemedToast(Info.this, getResources().getString(R.string.upgrade_import_no_file_found, DeckPicker.IMPORT_REPLACE_COLLECTION_NAME), false); } else { lockScreenOrientation(); DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT_REPLACE, mUpgradeImportListener, new DeckTask.TaskData(AnkiDroidApp.getCol(), apkgFile.getAbsolutePath())); } } }); continueButton.setVisibility(View.GONE); break; case UPGRADE_SCREEN_AUTO_UPGRADE: sb.append(getString(R.string.deck_upgrade_auto_upgrade)); but.setText(R.string.back); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent result = new Intent(); result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_PC_UPGRADE); result.putExtra(TYPE_ANIMATION_RIGHT, true); setResult(RESULT_OK, result); finishWithAnimation(false); } }); syncButton.setText(getString(R.string.upgrade_deck_sync_from_ankiweb)); syncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { StyledDialog.Builder builder = new StyledDialog.Builder(Info.this); builder.setTitle(R.string.upgrade_deck_sync_from_ankiweb); builder.setIcon(R.drawable.ic_dialog_alert); builder.setMessage(getString(R.string.upgrade_deck_have_you_synced)); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { lockScreenOrientation(); downloadCollection(); } }); builder.setNegativeButton(R.string.back, null); builder.show(); } }); continueButton.setVisibility(View.GONE); break; } // File[] fileList = (new File(AnkiDroidApp.getCurrentAnkiDroidDirectory())).listFiles(new // OldAnkiDeckFilter()); // StringBuilder fsb = new StringBuilder(); // fsb.append("<ul>"); // for (File f : fileList) { // fsb.append("<li>").append(f.getName().replace(".anki", "")).append("</li>"); // } // fsb.append("</ul>"); // sb.append(res.getString(R.string.upgrade_decks_message, fsb.toString())); // sb.append("<ul><li>"); // sb.append(res.getString(R.string.upgrade_decks_message_pos1, // AnkiDroidApp.getCurrentAnkiDroidDirectory())); // sb.append("</li><li>"); // sb.append(res.getString(R.string.upgrade_decks_message_pos2, res.getString(R.string.link_anki))); // sb.append("</li><li>"); // sb.append(res.getString(R.string.upgrade_decks_message_pos3)); // sb.append("</li></ul>"); // sb.append(res.getString(R.string.upgrade_decks_message_finish)); sb.append("</body></html>"); mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null); StyledDialog.Builder builder2 = new StyledDialog.Builder(this); // builder2.setTitle(res.getString(R.string.connection_error_title)); builder2.setIcon(R.drawable.ic_dialog_alert); builder2.setMessage(res.getString(R.string.youre_offline)); builder2.setPositiveButton(res.getString(R.string.dialog_ok), null); mNoConnectionAlert = builder2.create(); break; default: finish(); break; } }
From source file:org.openhab.habdroid.ui.OpenHABWidgetAdapter.java
@SuppressWarnings("deprecation") @Override/* ww w . java 2 s.c o m*/ public View getView(int position, View convertView, ViewGroup parent) { /* TODO: This definitely needs some huge refactoring */ final RelativeLayout widgetView; TextView labelTextView; TextView valueTextView; int widgetLayout; String[] splitString; OpenHABWidget openHABWidget = getItem(position); int screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getWidth(); switch (this.getItemViewType(position)) { case TYPE_FRAME: widgetLayout = R.layout.openhabwidgetlist_frameitem; break; case TYPE_GROUP: widgetLayout = R.layout.openhabwidgetlist_groupitem; break; case TYPE_SECTIONSWITCH: widgetLayout = R.layout.openhabwidgetlist_sectionswitchitem; break; case TYPE_SWITCH: widgetLayout = R.layout.openhabwidgetlist_switchitem; break; case TYPE_ROLLERSHUTTER: widgetLayout = R.layout.openhabwidgetlist_rollershutteritem; break; case TYPE_TEXT: widgetLayout = R.layout.openhabwidgetlist_textitem; break; case TYPE_SLIDER: widgetLayout = R.layout.openhabwidgetlist_slideritem; break; case TYPE_IMAGE: widgetLayout = R.layout.openhabwidgetlist_imageitem; break; case TYPE_SELECTION: widgetLayout = R.layout.openhabwidgetlist_selectionitem; break; case TYPE_SETPOINT: widgetLayout = R.layout.openhabwidgetlist_setpointitem; break; case TYPE_CHART: widgetLayout = R.layout.openhabwidgetlist_chartitem; break; case TYPE_VIDEO: widgetLayout = R.layout.openhabwidgetlist_videoitem; break; case TYPE_VIDEO_MJPEG: widgetLayout = R.layout.openhabwidgetlist_videomjpegitem; break; case TYPE_WEB: widgetLayout = R.layout.openhabwidgetlist_webitem; break; case TYPE_COLOR: widgetLayout = R.layout.openhabwidgetlist_coloritem; break; default: widgetLayout = R.layout.openhabwidgetlist_genericitem; break; } if (convertView == null) { widgetView = new RelativeLayout(getContext()); String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi; vi = (LayoutInflater) getContext().getSystemService(inflater); vi.inflate(widgetLayout, widgetView, true); } else { widgetView = (RelativeLayout) convertView; } // Process the colour attributes Integer iconColor = openHABWidget.getIconColor(); Integer labelColor = openHABWidget.getLabelColor(); Integer valueColor = openHABWidget.getValueColor(); // Process widgets icon image MySmartImageView widgetImage = (MySmartImageView) widgetView.findViewById(R.id.widgetimage); // Some of widgets, for example Frame doesnt' have an icon, so... if (widgetImage != null) { if (openHABWidget.getIcon() != null) { // This is needed to escape possible spaces and everything according to rfc2396 String iconUrl = openHABBaseUrl + "images/" + Uri.encode(openHABWidget.getIcon() + ".png"); // Log.d(TAG, "Will try to load icon from " + iconUrl); // Now set image URL widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon, openHABUsername, openHABPassword); if (iconColor != null) widgetImage.setColorFilter(iconColor); else widgetImage.clearColorFilter(); } } TextView defaultTextView = new TextView(widgetView.getContext()); // Get TextView for widget label and set it's color labelTextView = (TextView) widgetView.findViewById(R.id.widgetlabel); // Change label color only for non-frame widgets if (labelColor != null && labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) { Log.d(TAG, String.format("Setting label color to %d", labelColor)); labelTextView.setTextColor(labelColor); } else if (labelTextView != null && this.getItemViewType(position) != TYPE_FRAME) labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); // Get TextView for widget value and set it's color valueTextView = (TextView) widgetView.findViewById(R.id.widgetvalue); if (valueColor != null && valueTextView != null) { Log.d(TAG, String.format("Setting value color to %d", valueColor)); valueTextView.setTextColor(valueColor); } else if (valueTextView != null) valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); defaultTextView = null; switch (getItemViewType(position)) { case TYPE_FRAME: if (labelTextView != null) { labelTextView.setText(openHABWidget.getLabel()); if (valueColor != null) labelTextView.setTextColor(valueColor); } widgetView.setClickable(false); if (openHABWidget.getLabel().length() > 0) { // hide empty frames widgetView.setVisibility(View.VISIBLE); labelTextView.setVisibility(View.VISIBLE); } else { widgetView.setVisibility(View.GONE); labelTextView.setVisibility(View.GONE); } break; case TYPE_GROUP: if (labelTextView != null && valueTextView != null) { splitString = openHABWidget.getLabel().split("\\[|\\]"); labelTextView.setText(splitString[0]); if (splitString.length > 1) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } } break; case TYPE_SECTIONSWITCH: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (splitString.length > 1 && valueTextView != null) { // We have some value valueTextView.setText(splitString[1]); } else { // This is needed to clean up cached TextViews valueTextView.setText(""); } RadioGroup sectionSwitchRadioGroup = (RadioGroup) widgetView.findViewById(R.id.sectionswitchradiogroup); // As we create buttons in this radio in runtime, we need to remove all // exiting buttons first sectionSwitchRadioGroup.removeAllViews(); sectionSwitchRadioGroup.setTag(openHABWidget); Iterator<OpenHABWidgetMapping> sectionMappingIterator = openHABWidget.getMappings().iterator(); while (sectionMappingIterator.hasNext()) { OpenHABWidgetMapping widgetMapping = sectionMappingIterator.next(); SegmentedControlButton segmentedControlButton = (SegmentedControlButton) LayoutInflater .from(sectionSwitchRadioGroup.getContext()) .inflate(R.layout.openhabwidgetlist_sectionswitchitem_button, sectionSwitchRadioGroup, false); segmentedControlButton.setText(widgetMapping.getLabel()); segmentedControlButton.setTag(widgetMapping.getCommand()); if (openHABWidget.getItem() != null && widgetMapping.getCommand() != null) { if (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { segmentedControlButton.setChecked(true); } else { segmentedControlButton.setChecked(false); } } else { segmentedControlButton.setChecked(false); } segmentedControlButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Log.i(TAG, "Button clicked"); RadioGroup group = (RadioGroup) view.getParent(); if (group.getTag() != null) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) view; if (selectedButton.getTag() != null) { sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } } }); sectionSwitchRadioGroup.addView(segmentedControlButton); } sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { OpenHABWidget radioWidget = (OpenHABWidget) group.getTag(); SegmentedControlButton selectedButton = (SegmentedControlButton) group.findViewById(checkedId); if (selectedButton != null) { Log.d(TAG, "Selected " + selectedButton.getText()); Log.d(TAG, "Command = " + (String) selectedButton.getTag()); // radioWidget.getItem().sendCommand((String)selectedButton.getTag()); sendItemCommand(radioWidget.getItem(), (String) selectedButton.getTag()); } } }); break; case TYPE_SWITCH: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); SwitchCompat switchSwitch = (SwitchCompat) widgetView.findViewById(R.id.switchswitch); if (openHABWidget.hasItem()) { if (openHABWidget.getItem().getStateAsBoolean()) { switchSwitch.setChecked(true); } else { switchSwitch.setChecked(false); } } switchSwitch.setTag(openHABWidget.getItem()); switchSwitch.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { SwitchCompat switchSwitch = (SwitchCompat) v; OpenHABItem linkedItem = (OpenHABItem) switchSwitch.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) if (!switchSwitch.isChecked()) { sendItemCommand(linkedItem, "ON"); } else { sendItemCommand(linkedItem, "OFF"); } return false; } }); break; case TYPE_COLOR: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton colorUpButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_up); ImageButton colorDownButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_down); ImageButton colorColorButton = (ImageButton) widgetView.findViewById(R.id.colorbutton_color); colorUpButton.setTag(openHABWidget.getItem()); colorDownButton.setTag(openHABWidget.getItem()); colorColorButton.setTag(openHABWidget.getItem()); colorUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "ON"); return false; } }); colorDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem, "OFF"); return false; } }); colorColorButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton colorButton = (ImageButton) v; OpenHABItem colorItem = (OpenHABItem) colorButton.getTag(); if (colorItem != null) { if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { Log.d(TAG, "Time to launch color picker!"); ColorPickerDialog colorDialog = new ColorPickerDialog(widgetView.getContext(), new OnColorChangedListener() { public void colorChanged(float[] hsv, View v) { Log.d(TAG, "New color HSV = " + hsv[0] + ", " + hsv[1] + ", " + hsv[2]); String newColor = String.valueOf(hsv[0]) + "," + String.valueOf(hsv[1] * 100) + "," + String.valueOf(hsv[2] * 100); OpenHABItem colorItem = (OpenHABItem) v.getTag(); sendItemCommand(colorItem, newColor); } }, colorItem.getStateAsHSV()); colorDialog.setTag(colorItem); colorDialog.show(); } } return false; } }); break; case TYPE_ROLLERSHUTTER: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); ImageButton rollershutterUpButton = (ImageButton) widgetView.findViewById(R.id.rollershutterbutton_up); ImageButton rollershutterStopButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_stop); ImageButton rollershutterDownButton = (ImageButton) widgetView .findViewById(R.id.rollershutterbutton_down); rollershutterUpButton.setTag(openHABWidget.getItem()); rollershutterStopButton.setTag(openHABWidget.getItem()); rollershutterDownButton.setTag(openHABWidget.getItem()); rollershutterUpButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "UP"); return false; } }); rollershutterStopButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "STOP"); return false; } }); rollershutterDownButton.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent motionEvent) { ImageButton rollershutterButton = (ImageButton) v; OpenHABItem rollershutterItem = (OpenHABItem) rollershutterButton.getTag(); if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem, "DOWN"); return false; } }); break; case TYPE_TEXT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) if (splitString.length > 0) { labelTextView.setText(splitString[0]); } else { labelTextView.setText(openHABWidget.getLabel()); } if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } else { // If value is empty, hide TextView to fix vertical alignment of label valueTextView.setVisibility(View.GONE); valueTextView.setText(""); } break; case TYPE_SLIDER: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); SeekBar sliderSeekBar = (SeekBar) widgetView.findViewById(R.id.sliderseekbar); if (openHABWidget.hasItem()) { sliderSeekBar.setTag(openHABWidget.getItem()); sliderSeekBar.setProgress(openHABWidget.getItem().getStateAsFloat().intValue()); sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } public void onStartTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStartTrackingTouch position = " + seekBar.getProgress()); } public void onStopTrackingTouch(SeekBar seekBar) { Log.d(TAG, "onStopTrackingTouch position = " + seekBar.getProgress()); OpenHABItem sliderItem = (OpenHABItem) seekBar.getTag(); // sliderItem.sendCommand(String.valueOf(seekBar.getProgress())); if (sliderItem != null && seekBar != null) sendItemCommand(sliderItem, String.valueOf(seekBar.getProgress())); } }); if (volumeUpWidget == null) { volumeUpWidget = sliderSeekBar; volumeDownWidget = sliderSeekBar; } } break; case TYPE_IMAGE: MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage); imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false, openHABUsername, openHABPassword); // ViewGroup.LayoutParams imageLayoutParams = imageImage.getLayoutParams(); // float imageRatio = imageImage.getDrawable().getIntrinsicWidth()/imageImage.getDrawable().getIntrinsicHeight(); // imageLayoutParams.height = (int) (screenWidth/imageRatio); // imageImage.setLayoutParams(imageLayoutParams); if (openHABWidget.getRefresh() > 0) { imageImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(imageImage); } break; case TYPE_CHART: MySmartImageView chartImage = (MySmartImageView) widgetView.findViewById(R.id.chartimage); //Always clear the drawable so no images from recycled views appear chartImage.setImageDrawable(null); OpenHABItem chartItem = openHABWidget.getItem(); Random random = new Random(); String chartUrl = ""; if (chartItem != null) { if (chartItem.getType().equals("GroupItem")) { chartUrl = openHABBaseUrl + "chart?groups=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } else { chartUrl = openHABBaseUrl + "chart?items=" + chartItem.getName() + "&period=" + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt()); } if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) { chartUrl += "&service=" + openHABWidget.getService(); } } Log.d(TAG, "Chart url = " + chartUrl); if (chartImage == null) Log.e(TAG, "chartImage == null !!!"); ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams(); chartLayoutParams.height = (int) (screenWidth / 2); chartImage.setLayoutParams(chartLayoutParams); chartUrl += "&w=" + String.valueOf(screenWidth); chartUrl += "&h=" + String.valueOf(screenWidth / 2); chartImage.setImageUrl(chartUrl, false, openHABUsername, openHABPassword); // TODO: This is quite dirty fix to make charts look full screen width on all displays if (openHABWidget.getRefresh() > 0) { chartImage.setRefreshRate(openHABWidget.getRefresh()); refreshImageList.add(chartImage); } Log.d(TAG, "chart size = " + chartLayoutParams.width + " " + chartLayoutParams.height); break; case TYPE_VIDEO: VideoView videoVideo = (VideoView) widgetView.findViewById(R.id.videovideo); Log.d(TAG, "Opening video at " + openHABWidget.getUrl()); // TODO: This is quite dirty fix to make video look maximum available size on all screens WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); ViewGroup.LayoutParams videoLayoutParams = videoVideo.getLayoutParams(); videoLayoutParams.height = (int) (wm.getDefaultDisplay().getWidth() / 1.77); videoVideo.setLayoutParams(videoLayoutParams); // We don't have any event handler to know if the VideoView is on the screen // so we manage an array of all videos to stop them when user leaves the page if (!videoWidgetList.contains(videoVideo)) videoWidgetList.add(videoVideo); // Start video if (!videoVideo.isPlaying()) { videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl())); videoVideo.start(); } Log.d(TAG, "Video height is " + videoVideo.getHeight()); break; case TYPE_VIDEO_MJPEG: Log.d(TAG, "Video is mjpeg"); ImageView mjpegImage = (ImageView) widgetView.findViewById(R.id.mjpegimage); MjpegStreamer mjpegStreamer = new MjpegStreamer(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword, this.getContext()); mjpegStreamer.setTargetImageView(mjpegImage); mjpegStreamer.start(); if (!mjpegWidgetList.contains(mjpegStreamer)) mjpegWidgetList.add(mjpegStreamer); break; case TYPE_WEB: WebView webWeb = (WebView) widgetView.findViewById(R.id.webweb); if (openHABWidget.getHeight() > 0) { ViewGroup.LayoutParams webLayoutParams = webWeb.getLayoutParams(); webLayoutParams.height = openHABWidget.getHeight() * 80; webWeb.setLayoutParams(webLayoutParams); } webWeb.setWebViewClient( new AnchorWebViewClient(openHABWidget.getUrl(), this.openHABUsername, this.openHABPassword)); webWeb.getSettings().setJavaScriptEnabled(true); webWeb.loadUrl(openHABWidget.getUrl()); break; case TYPE_SELECTION: int spinnerSelectedIndex = -1; if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); final Spinner selectionSpinner = (Spinner) widgetView.findViewById(R.id.selectionspinner); selectionSpinner.setOnItemSelectedListener(null); ArrayList<String> spinnerArray = new ArrayList<String>(); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings().iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); spinnerArray.add(openHABWidgetMapping.getLabel()); if (openHABWidgetMapping.getCommand() != null && openHABWidget.getItem() != null) if (openHABWidgetMapping.getCommand().equals(openHABWidget.getItem().getState())) { spinnerSelectedIndex = spinnerArray.size() - 1; } } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_spinner_item, spinnerArray); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); selectionSpinner.setAdapter(spinnerAdapter); selectionSpinner.setTag(openHABWidget); if (spinnerSelectedIndex >= 0) { Log.d(TAG, "Setting spinner selected index to " + String.valueOf(spinnerSelectedIndex)); selectionSpinner.setSelection(spinnerSelectedIndex); } else { Log.d(TAG, "Not setting spinner selected index"); } selectionSpinner.post(new Runnable() { @Override public void run() { selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int index, long id) { Log.d(TAG, "Spinner item click on index " + index); Spinner spinner = (Spinner) parent; String selectedLabel = (String) spinner.getAdapter().getItem(index); Log.d(TAG, "Spinner onItemSelected selected label = " + selectedLabel); OpenHABWidget openHABWidget = (OpenHABWidget) parent.getTag(); if (openHABWidget != null) { Log.d(TAG, "Label selected = " + openHABWidget.getMapping(index).getLabel()); Iterator<OpenHABWidgetMapping> mappingIterator = openHABWidget.getMappings() .iterator(); while (mappingIterator.hasNext()) { OpenHABWidgetMapping openHABWidgetMapping = mappingIterator.next(); if (openHABWidgetMapping.getLabel().equals(selectedLabel)) { Log.d(TAG, "Spinner onItemSelected found match with " + openHABWidgetMapping.getCommand()); if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() != null) { // Only send the command for selection of selected command will change the state if (!openHABWidget.getItem().getState() .equals(openHABWidgetMapping.getCommand())) { Log.d(TAG, "Spinner onItemSelected selected label command != current item state"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } else if (openHABWidget.getItem() != null && openHABWidget.getItem().getState() == null) { Log.d(TAG, "Spinner onItemSelected selected label command and state == null"); sendItemCommand(openHABWidget.getItem(), openHABWidgetMapping.getCommand()); } } } } // if (!openHABWidget.getItem().getState().equals(openHABWidget.getMapping(index).getCommand())) // sendItemCommand(openHABWidget.getItem(), // openHABWidget.getMapping(index).getCommand()); } public void onNothingSelected(AdapterView<?> arg0) { } }); } }); break; case TYPE_SETPOINT: splitString = openHABWidget.getLabel().split("\\[|\\]"); if (labelTextView != null) labelTextView.setText(splitString[0]); if (valueTextView != null) if (splitString.length > 1) { // If value is not empty, show TextView valueTextView.setVisibility(View.VISIBLE); valueTextView.setText(splitString[1]); } Button setPointMinusButton = (Button) widgetView.findViewById(R.id.setpointbutton_minus); Button setPointPlusButton = (Button) widgetView.findViewById(R.id.setpointbutton_plus); setPointMinusButton.setTag(openHABWidget); setPointPlusButton.setTag(openHABWidget); setPointMinusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Minus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue - setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); setPointPlusButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.d(TAG, "Plus"); OpenHABWidget setPointWidget = (OpenHABWidget) v.getTag(); float currentValue = setPointWidget.getItem().getStateAsFloat(); currentValue = currentValue + setPointWidget.getStep(); if (currentValue < setPointWidget.getMinValue()) currentValue = setPointWidget.getMinValue(); if (currentValue > setPointWidget.getMaxValue()) currentValue = setPointWidget.getMaxValue(); sendItemCommand(setPointWidget.getItem(), String.valueOf(currentValue)); } }); if (volumeUpWidget == null) { volumeUpWidget = setPointPlusButton; volumeDownWidget = setPointMinusButton; } break; default: if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel()); break; } LinearLayout dividerLayout = (LinearLayout) widgetView.findViewById(R.id.listdivider); if (dividerLayout != null) { if (position < this.getCount() - 1) { if (this.getItemViewType(position + 1) == TYPE_FRAME) { dividerLayout.setVisibility(View.GONE); // hide dividers before frame widgets } else { dividerLayout.setVisibility(View.VISIBLE); // show dividers for all others } } else { // last widget in the list, hide divider dividerLayout.setVisibility(View.GONE); } } return widgetView; }
From source file:com.eveningoutpost.dexdrip.Home.java
private void updateCurrentBgInfo(String source) { Log.d(TAG, "updateCurrentBgInfo from: " + source); if (!activityVisible) { Log.d(TAG, "Display not visible - not updating chart"); return;/*from ww w.ja va2s .c om*/ } if (reset_viewport) { reset_viewport = false; holdViewport.set(0, 0, 0, 0); if (chart != null) chart.setZoomType(ZoomType.HORIZONTAL); } setupCharts(); final TextView notificationText = (TextView) findViewById(R.id.notices); final TextView lowPredictText = (TextView) findViewById(R.id.lowpredict); if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) { notificationText.setTextSize(40); } notificationText.setText(""); notificationText.setTextColor(Color.RED); UndoRedo.purgeQueues(); if (UndoRedo.undoListHasItems()) { btnUndo.setVisibility(View.VISIBLE); showcasemenu(SHOWCASE_UNDO); } else { btnUndo.setVisibility(View.INVISIBLE); } if (UndoRedo.redoListHasItems()) { btnRedo.setVisibility(View.VISIBLE); showcasemenu(SHOWCASE_REDO); } else { btnRedo.setVisibility(View.INVISIBLE); } boolean isBTWixel = CollectionServiceStarter.isBTWixel(getApplicationContext()); // port this lot to DexCollectionType to avoid multiple lookups of the same preference boolean isDexbridgeWixel = CollectionServiceStarter.isDexBridgeOrWifiandDexBridge(); boolean isWifiBluetoothWixel = CollectionServiceStarter.isWifiandBTWixel(getApplicationContext()); isBTShare = CollectionServiceStarter.isBTShare(getApplicationContext()); isG5Share = CollectionServiceStarter.isBTG5(getApplicationContext()); boolean isWifiWixel = CollectionServiceStarter.isWifiWixel(getApplicationContext()); alreadyDisplayedBgInfoCommon = false; // reset flag if (isBTShare) { updateCurrentBgInfoForBtShare(notificationText); } if (isG5Share) { updateCurrentBgInfoCommon(notificationText); } if (isBTWixel || isDexbridgeWixel || isWifiBluetoothWixel) { updateCurrentBgInfoForBtBasedWixel(notificationText); } if (isWifiWixel || isWifiBluetoothWixel) { updateCurrentBgInfoForWifiWixel(notificationText); } else if (is_follower) { displayCurrentInfo(); getApplicationContext().startService(new Intent(getApplicationContext(), Notifications.class)); } else if (!alreadyDisplayedBgInfoCommon && DexCollectionType.getDexCollectionType() == DexCollectionType.LibreAlarm) { updateCurrentBgInfoCommon(notificationText); } if (prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n ALL ALERTS CURRENTLY DISABLED"); } else if (prefs.getLong("low_alerts_disabled_until", 0) > new Date().getTime() && prefs.getLong("high_alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n LOW AND HIGH ALERTS CURRENTLY DISABLED"); } else if (prefs.getLong("low_alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n LOW ALERTS CURRENTLY DISABLED"); } else if (prefs.getLong("high_alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n HIGH ALERTS CURRENTLY DISABLED"); } NavigationDrawerFragment navigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager() .findFragmentById(R.id.navigation_drawer); // DEBUG ONLY if ((BgGraphBuilder.last_noise > 0) && (prefs.getBoolean("show_noise_workings", false))) { notificationText.append("\nSensor Noise: " + JoH.qs(BgGraphBuilder.last_noise, 1)); if ((BgGraphBuilder.best_bg_estimate > 0) && (BgGraphBuilder.last_bg_estimate > 0)) { final double estimated_delta = BgGraphBuilder.best_bg_estimate - BgGraphBuilder.last_bg_estimate; notificationText.append("\nBG Original: " + bgGraphBuilder.unitized_string(BgReading.lastNoSenssor().calculated_value) + " \u0394 " + bgGraphBuilder.unitizedDeltaString(false, true, true) + " " + BgReading.lastNoSenssor().slopeArrow()); notificationText.append("\nBG Estimate: " + bgGraphBuilder.unitized_string(BgGraphBuilder.best_bg_estimate) + " \u0394 " + bgGraphBuilder.unitizedDeltaStringRaw(false, true, estimated_delta) + " " + BgReading.slopeToArrowSymbol(estimated_delta / (BgGraphBuilder.DEXCOM_PERIOD / 60000))); } } // TODO we need to consider noise level? // when to raise the alarm lowPredictText.setText(""); lowPredictText.setVisibility(View.INVISIBLE); if (BgGraphBuilder.low_occurs_at > 0) { final double low_predicted_alarm_minutes = Double .parseDouble(prefs.getString("low_predict_alarm_level", "50")); final double now = JoH.ts(); final double predicted_low_in_mins = (BgGraphBuilder.low_occurs_at - now) / 60000; if (predicted_low_in_mins > 1) { lowPredictText.append(getString(R.string.low_predicted) + "\n" + getString(R.string.in) + ": " + (int) predicted_low_in_mins + getString(R.string.space_mins)); if (predicted_low_in_mins < low_predicted_alarm_minutes) { lowPredictText.setTextColor(Color.RED); // low front getting too close! } else { final double previous_predicted_low_in_mins = (BgGraphBuilder.previous_low_occurs_at - now) / 60000; if ((BgGraphBuilder.previous_low_occurs_at > 0) && ((previous_predicted_low_in_mins + 5) < predicted_low_in_mins)) { lowPredictText.setTextColor(Color.GREEN); // low front is getting further away } else { lowPredictText.setTextColor(Color.YELLOW); // low front is getting nearer! } } lowPredictText.setVisibility(View.VISIBLE); } BgGraphBuilder.previous_low_occurs_at = BgGraphBuilder.low_occurs_at; } if (navigationDrawerFragment == null) Log.e("Runtime", "navigationdrawerfragment is null"); try { navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), menu_name, this); } catch (Exception e) { Log.e("Runtime", "Exception with navigrationdrawerfragment: " + e.toString()); } if (nexttoast != null) { toast(nexttoast); nexttoast = null; } // hide the treatment recognition text after some seconds if ((last_speech_time > 0) && ((JoH.ts() - last_speech_time) > 20000)) { voiceRecognitionText.setVisibility(View.INVISIBLE); last_speech_time = 0; } if (ActivityRecognizedService.is_in_vehicle_mode()) { btnVehicleMode.setVisibility(View.VISIBLE); } else { btnVehicleMode.setVisibility(View.INVISIBLE); } //showcasemenu(1); // 3 dot menu }