List of usage examples for android.widget LinearLayout setOrientation
public void setOrientation(@OrientationMode int orientation)
From source file:com.flipzu.flipzu.Recorder.java
public void showFlipzuTipsOffline(LinearLayout cc, LayoutParams params, String msg) { final float scale = getResources().getDisplayMetrics().density; final int pixel_5 = 5 / (int) (scale + 0.5f); LinearLayout cl = new LinearLayout(Recorder.this); cl.setOrientation(LinearLayout.HORIZONTAL); cl.setPadding(0, 0, 0, pixel_5);/* w w w . ja v a2 s . c o m*/ /* comment */ String tips_username = "Flipzu Tips"; TextView comment_tv = new TextView(Recorder.this); comment_tv.setLayoutParams(params); comment_tv.setText(tips_username + ": " + msg, TextView.BufferType.SPANNABLE); comment_tv.setTextColor(Color.parseColor("#656565")); Spannable comment_span = (Spannable) comment_tv.getText(); comment_span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, comment_tv.getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_span.setSpan(new ForegroundColorSpan(Color.parseColor("#182e5b")), 0, tips_username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_tv.setText(comment_span); cl.addView(comment_tv); cc.addView(cl); }
From source file:com.neka.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject// w ww. j a v a 2 s .c o m */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); /* back.setText("<"); */ Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); //forward.setText(">"); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); //close.setText(buttonLabel); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar //toolbar.addView(actionButtonContainer); //toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. *///from w w w.j a va2 s. c o m public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); LayoutParams lp = new LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = LayoutParams.MATCH_PARENT; lp.height = LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:org.apache.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject// w w w .java 2 s . c o m */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); Resources activityRes = cordova.getActivity().getResources(); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); Drawable backIcon = activityRes.getDrawable(backResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackgroundDrawable(backIcon); } else { back.setBackground(backIcon); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); Drawable fwdIcon = activityRes.getDrawable(fwdResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { forward.setBackgroundDrawable(fwdIcon); } else { forward.setBackground(fwdIcon); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); Drawable closeIcon = activityRes.getDrawable(closeResId); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { close.setBackgroundDrawable(closeIcon); } else { close.setBackground(closeIcon); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:io.github.trulyfree.easyaspi.MainActivity.java
@Override public boolean setup() { downloadHandler = new DownloadHandler(this); fileHandler = new FileHandler(this); moduleHandler = new ModuleHandler(this); executorService = Executors.newCachedThreadPool(); setContentView(R.layout.activity_main); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override/* ww w. j av a2 s . c o m*/ public boolean onNavigationItemSelected(@NonNull MenuItem item) { ViewSwitcher viewGroup = (ViewSwitcher) findViewById(R.id.content); int id = item.getItemId(); if ((id == R.id.navigation_home || id == R.id.navigation_modules) && id != currentID) { currentID = item.getItemId(); viewGroup.showNext(); return true; } return false; } }); ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.content); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); viewSwitcher.setInAnimation(in); viewSwitcher.setOutAnimation(out); resetConfigReturned(); Button getNewModule = (Button) findViewById(R.id.new_module_config_confirm); getNewModule.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText editText = (EditText) findViewById(R.id.new_module_config_configurl); final String url = editText.getText().toString(); Toast.makeText(MainActivity.this, "Requested config from: " + url, Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { ModuleConfig config; try { config = moduleHandler.getModuleConfig(url); } catch (MalformedURLException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Invalid URL. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Failed to get module config. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (JsonParseException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Config loaded was invalid. :(", Toast.LENGTH_LONG).show(); } }); return false; } final ModuleConfig finalConfig = config; final ImageView configResponseBlock = (ImageView) findViewById(R.id.block_module_returned); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { LinearLayout layout = (LinearLayout) findViewById(R.id.module_returned_config); EditText moduleName = (EditText) findViewById(R.id.module_returned_configname); EditText moduleVersion = (EditText) findViewById( R.id.module_returned_configversion); EditText moduleConfigUrl = (EditText) findViewById(R.id.module_returned_configurl); EditText moduleJarUrl = (EditText) findViewById(R.id.module_returned_jarurl); LinearLayout moduleDependencies = (LinearLayout) findViewById( R.id.module_returned_dependencies); moduleDependencies.removeAllViewsInLayout(); try { configResponseBlock.setVisibility(View.GONE); moduleName.setText(finalConfig.getName()); moduleVersion.setText(finalConfig.getVersion()); moduleConfigUrl.setText(finalConfig.getConfUrl()); moduleJarUrl.setText(finalConfig.getJarUrl()); Config[] dependencies = finalConfig.getDependencies(); for (Config dependency : dependencies) { LinearLayout dependencyLayout = new LinearLayout(MainActivity.this); dependencyLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dependencyLayout.setOrientation(LinearLayout.HORIZONTAL); EditText name = new EditText(MainActivity.this); EditText jarUrl = new EditText(MainActivity.this); EditText[] loopThrough = { name, jarUrl }; LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f); for (EditText item : loopThrough) { item.setLayoutParams(params); item.setClickable(false); item.setInputType(InputType.TYPE_NULL); item.setCursorVisible(false); item.setFocusable(false); item.setFocusableInTouchMode(false); } name.setText(dependency.getName()); jarUrl.setText(dependency.getJarUrl()); dependencyLayout.addView(name); dependencyLayout.addView(jarUrl); moduleDependencies.addView(dependencyLayout); } layout.setClickable(true); Button validate = (Button) findViewById(R.id.module_returned_validate); Button cancel = (Button) findViewById(R.id.module_returned_cancel); validate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Requesting jars...", Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { try { boolean success = true, refreshAllModification = true; Button refreshAll = null, getNewModule = (Button) findViewById( R.id.new_module_config_confirm); try { refreshAll = (Button) findViewById(R.id.refresh_all); refreshAll.setClickable(false); } catch (Throwable e) { refreshAllModification = false; } getNewModule.setClickable(false); final TextView stager = (TextView) findViewById( R.id.new_module_config_downloadstage); final ProgressBar progressBar = (ProgressBar) findViewById( R.id.new_module_config_downloadprogress); try { runOnUiThread(new Runnable() { @Override public void run() { resetConfigReturned(); } }); moduleHandler.getNewModule( makeModuleCallback(stager, progressBar), finalConfig, null, true); } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { stager.setText(""); progressBar.setProgress(0); } }); success = false; } getNewModule.setClickable(true); if (refreshAllModification) { refreshAll.setClickable(true); } return success; } catch (Throwable throwable) { throwable.printStackTrace(); return false; } } }); } }); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Cancelling request...", Toast.LENGTH_SHORT).show(); resetConfigReturned(); } }); } catch (Exception e) { e.printStackTrace(); Toast.makeText(MainActivity.this, "Module config invalid. :(", Toast.LENGTH_LONG).show(); layout.setClickable(false); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock .setBackgroundColor((Integer) animator.getAnimatedValue()); } }); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); runOnUiThread(new Runnable() { @Override public void run() { colorAnimation.start(); } }); return true; } }); } }); moduleHandler.setup(); refreshFilling(); return true; }
From source file:org.apache.cordova.plugins.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/* w w w . ja v a 2 s . c o m*/ */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", EXIT_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); back.setText("<"); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); forward.setText(">"); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); close.setText(buttonLabel); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout /*cemerson*/ if (arrowButtonsAllowed) { actionButtonContainer.addView(back); actionButtonContainer.addView(forward); } // ================================================ // CHANGING per: // http://stackoverflow.com/a/16596554/826308 // *** ORIG CODE *** // // Add the views to our toolbar // toolbar.addView(actionButtonContainer); // toolbar.addView(edittext); // toolbar.addView(close); // // Don't add the toolbar if its been disabled // if (getShowLocationBar()) { // // Add our toolbar to our main view/layout // main.addView(toolbar); // } // *** CHANGED CODE *** // Add the views to our toolbar toolbar.addView(actionButtonContainer); if (getShowLocationBar()) { toolbar.addView(edittext); } toolbar.addView(close); // Add our toolbar to our main view/layout main.addView(toolbar); // ================================================ // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.flipzu.flipzu.Recorder.java
@Override public void onCommentsReceived(Hashtable<String, String>[] comments) { debug.logV(TAG, "onCommentsReceived"); final LinearLayout cc = (LinearLayout) findViewById(R.id.comments_container); /* cleanup comments first */ cc.removeAllViews();/*w w w. j a v a2s. co m*/ /* get pixel values for various DIPs */ final float scale = getResources().getDisplayMetrics().density; // final int pixel_10 = 10 / (int) (scale + 0.5f); final int pixel_5 = 5 / (int) (scale + 0.5f); // final int pixel_30 = 30 / (int) (scale + 0.5f); final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (comments != null && comments.length > 0) { for (int i = 0; i < comments.length; i++) { LinearLayout cl = new LinearLayout(Recorder.this); cl.setOrientation(LinearLayout.HORIZONTAL); cl.setPadding(0, 0, 0, pixel_5); debug.logD(TAG, "Refresher comment " + comments[i]); /* comment */ TextView comment_tv = new TextView(Recorder.this); comment_tv.setLayoutParams(params); comment_tv.setText(comments[i].get("username") + ": " + comments[i].get("comment"), TextView.BufferType.SPANNABLE); comment_tv.setTextColor(Color.parseColor("#656565")); Spannable comment_span = (Spannable) comment_tv.getText(); comment_span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, comment_tv.getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_span.setSpan(new ForegroundColorSpan(Color.parseColor("#182e5b")), 0, comments[i].get("username").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_tv.setText(comment_span); cl.addView(comment_tv); cc.addView(cl); } } else { if (mState == recorderState.RECORDING) { String msg = "You're LIVE! Your broadcast can be heard at http://flipzu.com/" + mUser.getUsername(); showFlipzuTipsOffline(cc, params, msg); } else { String msg = "Pick a good and descriptive broadcast title. A great title will attract more listeners!"; showFlipzuTipsOffline(cc, params, msg); msg = "You can disable sharing in Twitter and Facebook by clicking the logo buttons. This is great for testing."; showFlipzuTipsOffline(cc, params, msg); msg = "Press the \"Start Broadcast\" button and let them hear you!"; showFlipzuTipsOffline(cc, params, msg); } } }
From source file:org.telegram.ui.ProfileNotificationsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override//from w w w . j ava 2 s. co m public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5)); frameLayout.addView(listView); final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setAdapter(new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == settingsVibrateRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate)); builder.setItems( new CharSequence[] { LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled), LocaleController.getString("SettingsDefault", R.string.SettingsDefault), LocaleController.getString("SystemDefault", R.string.SystemDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (which == 0) { editor.putInt("vibrate_" + dialog_id, 2); } else if (which == 1) { editor.putInt("vibrate_" + dialog_id, 0); } else if (which == 2) { editor.putInt("vibrate_" + dialog_id, 4); } else if (which == 3) { editor.putInt("vibrate_" + dialog_id, 1); } else if (which == 4) { editor.putInt("vibrate_" + dialog_id, 3); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsNotificationsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems( new CharSequence[] { LocaleController.getString("Default", R.string.Default), LocaleController.getString("Enabled", R.string.Enabled), LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("notify2_" + dialog_id, which); if (which == 2) { NotificationsController.getInstance() .removeNotificationsForDialog(dialog_id); } MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0); editor.commit(); TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict .get(dialog_id); if (dialog != null) { dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); if (which == 2) { dialog.notify_settings.mute_until = Integer.MAX_VALUE; } } if (listView != null) { listView.invalidateViews(); } NotificationsController.updateServerNotificationsSettings(dialog_id); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsSoundRow) { try { Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Uri currentSound = null; String defaultPath = null; Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI; if (defaultUri != null) { defaultPath = defaultUri.getPath(); } String path = preferences.getString("sound_path_" + dialog_id, defaultPath); if (path != null && !path.equals("NoSound")) { if (path.equals(defaultPath)) { currentSound = defaultUri; } else { currentSound = Uri.parse(path); } } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); startActivityForResult(tmpIntent, 12); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == settingsLedRow) { if (getParentActivity() == null) { return; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity()); linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (preferences.contains("color_" + dialog_id)) { colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00)); } else { if ((int) dialog_id < 0) { colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00)); } else { colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00)); } } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("color_" + dialog_id, colorPickerView.getColor()); editor.commit(); listView.invalidateViews(); } }); builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("color_" + dialog_id, 0); editor.commit(); listView.invalidateViews(); } }); builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.remove("color_" + dialog_id); editor.commit(); listView.invalidateViews(); } }); showDialog(builder.create()); } else if (i == settingsPriorityRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority)); builder.setItems( new CharSequence[] { LocaleController.getString("SettingsDefault", R.string.SettingsDefault), LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault), LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh), LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { which = 3; } else { which--; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("priority_" + dialog_id, which).commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == smartRow) { if (getParentActivity() == null) { return; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount == 0) { notifyMaxCount = 2; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2 .getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); TextView textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsSoundAtMost", R.string.SmartNotificationsSoundAtMost)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerTimes = new NumberPicker(getParentActivity()); numberPickerTimes.setMinValue(1); numberPickerTimes.setMaxValue(10); numberPickerTimes.setValue(notifyMaxCount); linearLayout2.addView(numberPickerTimes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerTimes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerTimes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsTimes", R.string.SmartNotificationsTimes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsWithin", R.string.SmartNotificationsWithin)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerMinutes = new NumberPicker(getParentActivity()); numberPickerMinutes.setMinValue(1); numberPickerMinutes.setMaxValue(10); numberPickerMinutes.setValue(notifyDelay / 60); linearLayout2.addView(numberPickerMinutes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerMinutes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerMinutes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsMinutes", R.string.SmartNotificationsMinutes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("SmartNotifications", R.string.SmartNotifications)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit() .putInt("smart_max_count_" + dialog_id, numberPickerTimes.getValue()) .commit(); preferences.edit() .putInt("smart_delay_" + dialog_id, numberPickerMinutes.getValue() * 60) .commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled", R.string.SmartNotificationsDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("smart_max_count_" + dialog_id, 0).commit(); if (listView != null) { listView.invalidateViews(); } } }); showDialog(builder.create()); } } }); return fragmentView; }
From source file:org.solovyev.android.messenger.BaseListFragment.java
@Nonnull private View createListView() { final Context context = getThemeContext(); final FrameLayout root = new FrameLayout(context); // ------------------------------------------------------------------ final LinearLayout progressContainer = new LinearLayout(context); progressContainer.setId(INTERNAL_PROGRESS_CONTAINER_ID); progressContainer.setOrientation(VERTICAL); progressContainer.setVisibility(GONE); progressContainer.setGravity(CENTER); final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge); progressContainer.addView(progress, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); root.addView(progressContainer, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); // ------------------------------------------------------------------ final FrameLayout listViewContainer = new FrameLayout(context); listViewContainer.setId(INTERNAL_LIST_CONTAINER_ID); final TextView emptyListCaption = new TextView(context); emptyListCaption.setId(INTERNAL_EMPTY_ID); emptyListCaption.setGravity(CENTER); listViewContainer.addView(emptyListCaption, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); final ListViewAwareOnRefreshListener topRefreshListener = getTopPullRefreshListener(); final ListViewAwareOnRefreshListener bottomRefreshListener = getBottomPullRefreshListener(); final View listView; if (topRefreshListener == null && bottomRefreshListener == null) { pullToRefreshMode = null;/*from w ww . ja v a 2 s. c o m*/ listView = createListView(context); } else { listView = createPullToRefreshListView(context, topRefreshListener, bottomRefreshListener); } listViewContainer.addView(listView, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); root.addView(listViewContainer, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); // ------------------------------------------------------------------ root.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT)); return root; }
From source file:com.juick.android.ThreadFragment.java
public void showThread(JuickMessage jmsg, boolean keepShow) { if (jmsg.getReplyTo() != 0) { JuickMessage reply = jmsg;/*from w w w .ja v a2s.c om*/ LinearLayout ll = new LinearLayout(getActivity()); ll.setOrientation(LinearLayout.VERTICAL); ll.setBackgroundDrawable(new ColorDrawable(Color.WHITE)); int totalCount = 0; while (reply != null) { totalCount += reply.Text.length(); if (totalCount > 500 || ll.getChildCount() > 10) break; JuickMessagesAdapter.ParsedMessage parsedMessage = JuickMessagesAdapter .formatMessageText(getActivity(), reply, true); TextView child = new TextView(getActivity()); ll.addView(child, 0); child.setText(parsedMessage.textContent); if (reply.getReplyTo() < 1) break; reply = findReply(getListView(), reply.getReplyTo()); } if (ll.getChildCount() != 0) { int xy[] = new int[2]; getListView().getLocationOnScreen(xy); int windowHeight = getActivity().getWindow().getWindowManager().getDefaultDisplay().getHeight(); int listBottom = getListView().getHeight() + xy[1]; int bottomSize = windowHeight - listBottom; ll.setPressed(true); MainActivity.restyleChildrenOrWidget(ll); if (!keepShow || shownThreadToast.getView().getParent() == null) { // new or already hidden shownThreadToast = new Toast(getActivity()); shownThreadToast.setView(ll); shownThreadToast.setGravity(Gravity.BOTTOM | Gravity.LEFT, 0, bottomSize); shownThreadToast.setDuration(Toast.LENGTH_LONG); } shownThreadToast.show(); } } }