List of usage examples for android.widget TextView TextView
public TextView(Context context)
From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java
private static TextView getTextView(Context context, LinearLayout.LayoutParams params, StringBuffer buffer) { TextView textView = new TextView(context); textView.setTextColor(Color.BLACK); textView.setLayoutParams(params);// www . ja v a2s.com textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setTextSize(getTextSize(context)); textView.setText(Html.fromHtml(buffer.toString())); return textView; }
From source file:eu.operando.operandoapp.OperandoProxyStatus.java
@Override protected void onCreate(Bundle savedInstanceState) { MainUtil.initializeMainContext(getApplicationContext()); Settings settings = mainContext.getSettings(); settings.initializeDefaultValues();// ww w.ja v a2s . c om setCurrentThemeStyle(settings.getThemeStyle()); setTheme(getCurrentThemeStyle().themeAppCompatStyle()); super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); settings.registerOnSharedPreferenceChangeListener(this); webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); //region Floating Action Button fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class) && !MainUtil.isProxyPaused(mainContext)) { //Update Preferences to BypassProxy MainUtil.setProxyPaused(mainContext, true); fab.setImageResource(android.R.drawable.ic_media_play); //Toast.makeText(mainContext.getContext(), "-- bypass (disable) proxy --", Toast.LENGTH_SHORT).show(); } else if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class) && MainUtil.isProxyPaused(mainContext)) { MainUtil.setProxyPaused(mainContext, false); fab.setImageResource(android.R.drawable.ic_media_pause); //Toast.makeText(mainContext.getContext(), "-- re-enable proxy --", Toast.LENGTH_SHORT).show(); } else if (!mainContext.getAuthority() .aliasFile(BouncyCastleSslEngineSource.KEY_STORE_FILE_EXTENSION).exists()) { try { installCert(); } catch (RootCertificateException | GeneralSecurityException | OperatorCreationException | IOException ex) { Logger.error(this, ex.getMessage(), ex.getCause()); } } } }); //endregion //region TabHost final TabHost tabHost = (TabHost) findViewById(R.id.tabHost2); tabHost.setup(); TabHost.TabSpec tabSpec = tabHost.newTabSpec("wifi_ap"); tabSpec.setContent(R.id.WifiAndAccessPointsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_home)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("response_domain_filters"); tabSpec.setContent(R.id.ResponseAndDomainFiltersScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_filter)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("pending_notifications"); tabSpec.setContent(R.id.PendingNotificationsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_pending_notification)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("logs"); tabSpec.setContent(R.id.LogsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_report)); tabHost.addTab(tabSpec); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { switch (tabId) { case "pending_notifications": //region Load Tab3 ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.PendingNotificationsScrollView)) .getChildAt(0)).getChildAt(1)).removeAllViews(); LoadPendingNotificationsTab(); //endregion break; case "logs": //region Load Tab 4 //because it is a heavy task it is being loaded asynchronously ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)).getChildAt(0)) .getChildAt(1)).removeAllViews(); new AsyncTask() { private ProgressDialog mProgress; private List<String[]> apps; @Override protected void onPreExecute() { super.onPreExecute(); mProgress = new ProgressDialog(MainActivity.this); mProgress.setCancelable(false); mProgress.setCanceledOnTouchOutside(false); mProgress.setTitle("Fetching Application Data Logs"); mProgress.show(); } @Override protected Object doInBackground(Object[] params) { apps = new ArrayList(); for (String[] app : getInstalledApps(false)) { apps.add(new String[] { app[0], GetDataForApp(Integer.parseInt(app[1])) }); } return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); mProgress.dismiss(); for (String[] app : apps) { if (app[0].contains(".")) { continue; } TextView tv = new TextView(MainActivity.this); tv.setTextSize(18); tv.setText(app[0] + " || " + app[1]); ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)) .getChildAt(0)).getChildAt(1)).addView(tv); View separator = new View(MainActivity.this); separator.setBackgroundColor(Color.BLACK); separator.setLayoutParams( new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 5)); ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)) .getChildAt(0)).getChildAt(1)).addView(separator); } } }.execute(); //endregion break; } } }); //endregion //region Buttons WiFiAPButton = (Button) findViewById(R.id.WiFiAPButton); WiFiAPButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(mainContext.getContext(), AccessPointsActivity.class); startActivity(i); } }); responseFiltersButton = (Button) findViewById(R.id.responseFiltersButton); responseFiltersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), ResponseFiltersActivity.class); startActivity(i); } }); domainFiltersButton = (Button) findViewById(R.id.domainFiltersButton); domainFiltersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), DomainFiltersActivity.class); startActivity(i); } }); domainManagerButton = (Button) findViewById(R.id.domainManagerButton); domainManagerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), DomainManagerActivity.class); startActivity(i); } }); permissionsPerDomainButton = (Button) findViewById(R.id.permissionsPerDomainButton); permissionsPerDomainButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), PermissionsPerDomainActivity.class); startActivity(i); } }); trustedAccessPointsButton = (Button) findViewById(R.id.trustedAccessPointsButton); trustedAccessPointsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), TrustedAccessPointsActivity.class); startActivity(i); } }); updateButton = (Button) findViewById(R.id.updateButton); updateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // mark first time has not runned and update like it's initial . final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("firstTime", true); editor.commit(); DownloadInitialSettings(); } }); statisticsButton = (Button) findViewById(R.id.statisticsButton); statisticsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), StatisticsActivity.class); startActivity(i); } }); //endregion //region Action Bar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { setTitle(R.string.app_name); } //endregion //region Send Cached Settings //send cached settings if exist... BufferedReader br = null; try { File file = new File(MainContext.INSTANCE.getContext().getFilesDir(), "resend.inf"); StringBuilder content = new StringBuilder(); br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { content.append(line); } if (content.toString().equals("1")) { File f = new File(file.getCanonicalPath()); f.delete(); new DatabaseHelper(MainActivity.this) .sendSettingsToServer(new RequestFilterUtil(MainActivity.this).getIMEI()); } } catch (Exception ex) { ex.getMessage(); } finally { try { br.close(); } catch (Exception ex) { ex.getMessage(); } } //endregion initializeProxyService(); }
From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java
/** * @param fieldTable/*from ww w . j av a 2 s .c o m*/ * @param nameOfField * @param field */ private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal, final String fieldRemote) { if (mCurrentLocal == null || mCurrentSugar == null) return; // String fieldLocal = mCurrentLocal.get(nameOfField); // String fieldRemote = mCurrentSugar.get(nameOfField); TableRow row = new TableRow(this); final Spinner sourceSelect = new Spinner(this); sourceSelect.setBackgroundResource(R.drawable.black_underline); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources)); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sourceSelect.setAdapter(spinnerArrayAdapter); // Open the spinner when pressing any of the text fields OnClickListener spinnerOpener = new OnClickListener() { @Override public void onClick(View v) { sourceSelect.performClick(); } }; row.addView(sourceSelect); fieldTable.addView(row); row = new TableRow(this); TextView fieldName = new TextView(this); int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName()); fieldName.setText(this.getString(stringId)); fieldName.setTextSize(16); fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(), fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom()); fieldName.setOnClickListener(spinnerOpener); row.addView(fieldName); final TextView fieldValueLocal = new TextView(this); fieldValueLocal.setText(fieldLocal); fieldValueLocal.setTextSize(16); row.addView(fieldValueLocal); fieldValueLocal.setOnClickListener(spinnerOpener); fieldTable.addView(row); row = new TableRow(this); row.addView(new TextView(this));// add dummy control final TextView fieldValueRemote = new TextView(this); fieldValueRemote.setText(fieldRemote); fieldValueRemote.setTextSize(16); fieldValueRemote.setOnClickListener(spinnerOpener); row.addView(fieldValueRemote); sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); resolvedContacts[mPosResolved].set(nameOfField, fieldLocal); } else { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); resolvedContacts[mPosResolved].set(nameOfField, fieldRemote); } } @Override public void onNothingSelected(AdapterView<?> view) { } }); row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10); // Restore appropiate selections according to resolved contact if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) { sourceSelect.setSelection(0); } else { sourceSelect.setSelection(1); } fieldTable.addView(row); }
From source file:jp.ne.sakura.kkkon.android.exceptionhandler.testapp.ExceptionHandlerReportApp.java
/** Called when the activity is first created. */ @Override// w ww . j a va 2 s .c o m public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { ExceptionHandler.initialize(context); if (ExceptionHandler.needReport()) { final String fileName = ExceptionHandler.getBugReportFileAbsolutePath(); final File file = new File(fileName); final File fileZip; { String strFileZip = file.getAbsolutePath(); { int index = strFileZip.lastIndexOf('.'); if (0 < index) { strFileZip = strFileZip.substring(0, index); strFileZip += ".zip"; } } Log.d(TAG, strFileZip); fileZip = new File(strFileZip); if (fileZip.exists()) { fileZip.delete(); } } if (file.exists()) { Log.d(TAG, file.getAbsolutePath()); InputStream inStream = null; ZipOutputStream outStream = null; try { inStream = new FileInputStream(file); String strFileName = file.getAbsolutePath(); { int index = strFileName.lastIndexOf(File.separatorChar); if (0 < index) { strFileName = strFileName.substring(index + 1); } } Log.d(TAG, strFileName); outStream = new ZipOutputStream(new FileOutputStream(fileZip)); byte[] buff = new byte[8124]; { ZipEntry entry = new ZipEntry(strFileName); outStream.putNextEntry(entry); int len = 0; while (0 < (len = inStream.read(buff))) { outStream.write(buff, 0, len); } outStream.closeEntry(); } outStream.finish(); outStream.flush(); } catch (IOException e) { Log.e(TAG, "got exception", e); } finally { if (null != outStream) { try { outStream.close(); } catch (Exception e) { } } outStream = null; if (null != inStream) { try { inStream.close(); } catch (Exception e) { } } inStream = null; } Log.i(TAG, "zip created"); } if (file.exists()) { // upload or send e-mail InputStream inStream = null; StringBuilder sb = new StringBuilder(); try { inStream = new FileInputStream(file); byte[] buff = new byte[8124]; int readed = 0; do { readed = inStream.read(buff); for (int i = 0; i < readed; i++) { sb.append((char) buff[i]); } } while (readed >= 0); final String str = sb.toString(); Log.i(TAG, str); } catch (IOException e) { Log.e(TAG, "got exception", e); } finally { if (null != inStream) { try { inStream.close(); } catch (Exception e) { } } inStream = null; } AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); final Locale defaultLocale = Locale.getDefault(); String title = ""; String message = ""; String positive = ""; String negative = ""; boolean needDefaultLang = true; if (null != defaultLocale) { if (defaultLocale.equals(Locale.JAPANESE) || defaultLocale.equals(Locale.JAPAN)) { title = ""; message = "?????????"; positive = "?"; negative = ""; needDefaultLang = false; } } if (needDefaultLang) { title = "ERROR"; message = "Got unexpected error. Do you want to send information of error."; positive = "Send"; negative = "Cancel"; } alertDialog.setTitle(title); alertDialog.setMessage(message); alertDialog.setPositiveButton(positive + " mail", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface di, int i) { DefaultUploaderMailClient.upload(context, file, new String[] { "diverKon+sakura@gmail.com" }); } }); alertDialog.setNeutralButton(positive + " http", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface di, int i) { DefaultUploaderWeb.upload(ExceptionHandlerReportApp.this, fileZip, "http://kkkon.sakura.ne.jp/android/bug"); } }); alertDialog.setNegativeButton(negative, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface di, int i) { ExceptionHandler.clearReport(); } }); alertDialog.show(); } // TODO separate activity for crash report //DefaultCheckerAPK.checkAPK( this, null ); } ExceptionHandler.registHandler(); } super.onCreate(savedInstanceState); /* Create a TextView and set its content. * the text is retrieved by calling a native * function. */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("ExceptionHandler"); layout.addView(tv); Button btn1 = new Button(this); btn1.setText("invoke Exception"); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final int count = 2; int[] array = new int[count]; int value = array[count]; // invoke IndexOutOfBOundsException } }); layout.addView(btn1); Button btn2 = new Button(this); btn2.setText("reinstall apk"); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean foundApk = false; { final String apkPath = context.getPackageCodePath(); // API8 Log.d(TAG, "PackageCodePath: " + apkPath); final File fileApk = new File(apkPath); if (fileApk.exists()) { foundApk = true; Intent promptInstall = new Intent(Intent.ACTION_VIEW); promptInstall.setDataAndType(Uri.fromFile(fileApk), "application/vnd.android.package-archive"); promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(promptInstall); } } if (false == foundApk) { for (int i = 0; i < 10; ++i) { File fileApk = new File("/data/app/" + context.getPackageName() + "-" + i + ".apk"); Log.d(TAG, "check apk:" + fileApk.getAbsolutePath()); if (fileApk.exists()) { Log.i(TAG, "apk found. path=" + fileApk.getAbsolutePath()); /* * // require parmission { final String strCmd = "pm install -r " + fileApk.getAbsolutePath(); try { Runtime.getRuntime().exec( strCmd ); } catch ( IOException e ) { Log.e( TAG, "got exception", e ); } } */ Intent promptInstall = new Intent(Intent.ACTION_VIEW); promptInstall.setDataAndType(Uri.fromFile(fileApk), "application/vnd.android.package-archive"); promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(promptInstall); break; } } } } }); layout.addView(btn2); Button btn3 = new Button(this); btn3.setText("check apk"); btn3.setOnClickListener(new View.OnClickListener() { private boolean checkApk(final File fileApk, final ZipEntryFilter filter) { final boolean[] result = new boolean[1]; result[0] = true; final Thread thread = new Thread(new Runnable() { @Override public void run() { if (fileApk.exists()) { ZipFile zipFile = null; try { zipFile = new ZipFile(fileApk); List<ZipEntry> list = new ArrayList<ZipEntry>(zipFile.size()); for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) { ZipEntry ent = e.nextElement(); Log.d(TAG, ent.getName()); Log.d(TAG, "" + ent.getSize()); final boolean accept = filter.accept(ent); if (accept) { list.add(ent); } } Log.d(TAG, Build.CPU_ABI); // API 4 Log.d(TAG, Build.CPU_ABI2); // API 8 final String[] abiArray = { Build.CPU_ABI // API 4 , Build.CPU_ABI2 // API 8 }; String abiMatched = null; { boolean foundMatched = false; for (final String abi : abiArray) { if (null == abi) { continue; } if (0 == abi.length()) { continue; } for (final ZipEntry entry : list) { Log.d(TAG, entry.getName()); final String prefixABI = "lib/" + abi + "/"; if (entry.getName().startsWith(prefixABI)) { abiMatched = abi; foundMatched = true; break; } } if (foundMatched) { break; } } } Log.d(TAG, "matchedAbi=" + abiMatched); if (null != abiMatched) { boolean needReInstall = false; for (final ZipEntry entry : list) { Log.d(TAG, entry.getName()); final String prefixABI = "lib/" + abiMatched + "/"; if (entry.getName().startsWith(prefixABI)) { final String jniName = entry.getName().substring(prefixABI.length()); Log.d(TAG, "jni=" + jniName); final String strFileDst = context.getApplicationInfo().nativeLibraryDir + "/" + jniName; Log.d(TAG, strFileDst); final File fileDst = new File(strFileDst); if (!fileDst.exists()) { Log.w(TAG, "needReInstall: content missing " + strFileDst); needReInstall = true; } else { assert (entry.getSize() <= Integer.MAX_VALUE); if (fileDst.length() != entry.getSize()) { Log.w(TAG, "needReInstall: size broken " + strFileDst); needReInstall = true; } else { //org.apache.commons.io.IOUtils.contentEquals( zipFile.getInputStream( entry ), new FileInputStream(fileDst) ); final int size = (int) entry.getSize(); byte[] buffSrc = new byte[size]; { InputStream inStream = null; try { inStream = zipFile.getInputStream(entry); int pos = 0; { while (pos < size) { final int ret = inStream.read(buffSrc, pos, size - pos); if (ret <= 0) { break; } pos += ret; } } } catch (IOException e) { Log.d(TAG, "got exception", e); } finally { if (null != inStream) { try { inStream.close(); } catch (Exception e) { } } } } byte[] buffDst = new byte[(int) fileDst.length()]; { InputStream inStream = null; try { inStream = new FileInputStream(fileDst); int pos = 0; { while (pos < size) { final int ret = inStream.read(buffDst, pos, size - pos); if (ret <= 0) { break; } pos += ret; } } } catch (IOException e) { Log.d(TAG, "got exception", e); } finally { if (null != inStream) { try { inStream.close(); } catch (Exception e) { } } } } if (Arrays.equals(buffSrc, buffDst)) { Log.d(TAG, " content equal " + strFileDst); // OK } else { Log.w(TAG, "needReInstall: content broken " + strFileDst); needReInstall = true; } } } } } // for ZipEntry if (needReInstall) { // need call INSTALL APK Log.w(TAG, "needReInstall apk"); result[0] = false; } else { Log.d(TAG, "no need ReInstall apk"); } } } catch (IOException e) { Log.d(TAG, "got exception", e); } finally { if (null != zipFile) { try { zipFile.close(); } catch (Exception e) { } } } } } }); thread.setName("check jni so"); thread.start(); /* while ( thread.isAlive() ) { Log.d( TAG, "check thread.id=" + android.os.Process.myTid() + ",state=" + thread.getState() ); if ( ! thread.isAlive() ) { break; } AlertDialog.Builder alertDialog = new AlertDialog.Builder( ExceptionHandlerTestApp.this ); final Locale defaultLocale = Locale.getDefault(); String title = ""; String message = ""; String positive = ""; String negative = ""; boolean needDefaultLang = true; if ( null != defaultLocale ) { if ( defaultLocale.equals( Locale.JAPANESE ) || defaultLocale.equals( Locale.JAPAN ) ) { title = ""; message = "???????"; positive = "?"; negative = ""; needDefaultLang = false; } } if ( needDefaultLang ) { title = "INFO"; message = "Now checking installation. Cancel check?"; positive = "Wait"; negative = "Cancel"; } alertDialog.setTitle( title ); alertDialog.setMessage( message ); alertDialog.setPositiveButton( positive, null); alertDialog.setNegativeButton( negative, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface di, int i) { if ( thread.isAlive() ) { Log.d( TAG, "request interrupt" ); thread.interrupt(); } else { // nothing } } } ); if ( ! thread.isAlive() ) { break; } alertDialog.show(); if ( ! Thread.State.RUNNABLE.equals(thread.getState()) ) { break; } } */ try { thread.join(); } catch (InterruptedException e) { Log.d(TAG, "got exception", e); } return result[0]; } @Override public void onClick(View view) { boolean foundApk = false; { final String apkPath = context.getPackageCodePath(); // API8 Log.d(TAG, "PackageCodePath: " + apkPath); final File fileApk = new File(apkPath); this.checkApk(fileApk, new ZipEntryFilter() { @Override public boolean accept(ZipEntry entry) { if (entry.isDirectory()) { return false; } final String filename = entry.getName(); if (filename.startsWith("lib/")) { return true; } return false; } }); } } }); layout.addView(btn3); Button btn4 = new Button(this); btn4.setText("print dir and path"); btn4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { { final File file = context.getCacheDir(); Log.d(TAG, "Ctx.CacheDir=" + file.getAbsoluteFile()); } { final File file = context.getExternalCacheDir(); // API 8 if (null == file) { // no permission Log.d(TAG, "Ctx.ExternalCacheDir="); } else { Log.d(TAG, "Ctx.ExternalCacheDir=" + file.getAbsolutePath()); } } { final File file = context.getFilesDir(); Log.d(TAG, "Ctx.FilesDir=" + file.getAbsolutePath()); } { final String value = context.getPackageResourcePath(); Log.d(TAG, "Ctx.PackageResourcePath=" + value); } { final String[] files = context.fileList(); if (null == files) { Log.d(TAG, "Ctx.fileList=" + files); } else { for (final String filename : files) { Log.d(TAG, "Ctx.fileList=" + filename); } } } { final File file = Environment.getDataDirectory(); Log.d(TAG, "Env.DataDirectory=" + file.getAbsolutePath()); } { final File file = Environment.getDownloadCacheDirectory(); Log.d(TAG, "Env.DownloadCacheDirectory=" + file.getAbsolutePath()); } { final File file = Environment.getExternalStorageDirectory(); Log.d(TAG, "Env.ExternalStorageDirectory=" + file.getAbsolutePath()); } { final File file = Environment.getRootDirectory(); Log.d(TAG, "Env.RootDirectory=" + file.getAbsolutePath()); } { final ApplicationInfo appInfo = context.getApplicationInfo(); Log.d(TAG, "AppInfo.dataDir=" + appInfo.dataDir); Log.d(TAG, "AppInfo.nativeLibraryDir=" + appInfo.nativeLibraryDir); // API 9 Log.d(TAG, "AppInfo.publicSourceDir=" + appInfo.publicSourceDir); { final String[] sharedLibraryFiles = appInfo.sharedLibraryFiles; if (null == sharedLibraryFiles) { Log.d(TAG, "AppInfo.sharedLibraryFiles=" + sharedLibraryFiles); } else { for (final String fileName : sharedLibraryFiles) { Log.d(TAG, "AppInfo.sharedLibraryFiles=" + fileName); } } } Log.d(TAG, "AppInfo.sourceDir=" + appInfo.sourceDir); } { Log.d(TAG, "System.Properties start"); final Properties properties = System.getProperties(); if (null != properties) { for (final Object key : properties.keySet()) { String value = properties.getProperty((String) key); Log.d(TAG, " key=" + key + ",value=" + value); } } Log.d(TAG, "System.Properties end"); } { Log.d(TAG, "System.getenv start"); final Map<String, String> mapEnv = System.getenv(); if (null != mapEnv) { for (final Map.Entry<String, String> entry : mapEnv.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); Log.d(TAG, " key=" + key + ",value=" + value); } } Log.d(TAG, "System.getenv end"); } } }); layout.addView(btn4); Button btn5 = new Button(this); btn5.setText("check INSTALL_NON_MARKET_APPS"); btn5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SettingsCompat.initialize(context); if (SettingsCompat.isAllowedNonMarketApps()) { Log.d(TAG, "isAllowdNonMarketApps=true"); } else { Log.d(TAG, "isAllowdNonMarketApps=false"); } } }); layout.addView(btn5); Button btn6 = new Button(this); btn6.setText("send email"); btn6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent mailto = new Intent(); mailto.setAction(Intent.ACTION_SENDTO); mailto.setType("message/rfc822"); mailto.setData(Uri.parse("mailto:")); mailto.putExtra(Intent.EXTRA_EMAIL, new String[] { "" }); mailto.putExtra(Intent.EXTRA_SUBJECT, "[BugReport] " + context.getPackageName()); mailto.putExtra(Intent.EXTRA_TEXT, "body text"); //mailto.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); //context.startActivity( mailto ); Intent intent = Intent.createChooser(mailto, "Send Email"); if (null != intent) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { context.startActivity(intent); } catch (android.content.ActivityNotFoundException e) { Log.d(TAG, "got Exception", e); } } } }); layout.addView(btn6); Button btn7 = new Button(this); btn7.setText("upload http thread"); btn7.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.d(TAG, "brd=" + Build.BRAND); Log.d(TAG, "prd=" + Build.PRODUCT); //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); final Thread thread = new Thread(new Runnable() { @Override public void run() { Log.d(TAG, "upload thread tid=" + android.os.Process.myTid()); try { HttpPost httpPost = new HttpPost("http://kkkon.sakura.ne.jp/android/bug"); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); } Log.d(TAG, "upload finish"); } }); thread.setName("upload crash"); thread.start(); /* while ( thread.isAlive() ) { Log.d( TAG, "thread tid=" + android.os.Process.myTid() + ",state=" + thread.getState() ); if ( ! thread.isAlive() ) { break; } AlertDialog.Builder alertDialog = new AlertDialog.Builder( ExceptionHandlerTestApp.this ); final Locale defaultLocale = Locale.getDefault(); String title = ""; String message = ""; String positive = ""; String negative = ""; boolean needDefaultLang = true; if ( null != defaultLocale ) { if ( defaultLocale.equals( Locale.JAPANESE ) || defaultLocale.equals( Locale.JAPAN ) ) { title = ""; message = "???????"; positive = "?"; negative = ""; needDefaultLang = false; } } if ( needDefaultLang ) { title = "INFO"; message = "Now uploading error information. Cancel upload?"; positive = "Wait"; negative = "Cancel"; } alertDialog.setTitle( title ); alertDialog.setMessage( message ); alertDialog.setPositiveButton( positive, null); alertDialog.setNegativeButton( negative, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface di, int i) { if ( thread.isAlive() ) { Log.d( TAG, "request interrupt" ); thread.interrupt(); } else { // nothing } } } ); if ( ! thread.isAlive() ) { break; } alertDialog.show(); if ( ! Thread.State.RUNNABLE.equals(thread.getState()) ) { break; } } */ /* try { thread.join(); // must call. leak handle... } catch ( InterruptedException e ) { Log.d( TAG, "got Exception", e ); } */ } }); layout.addView(btn7); Button btn8 = new Button(this); btn8.setText("upload http AsyncTask"); btn8.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... paramss) { Boolean result = true; Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid()); try { //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); HttpPost httpPost = new HttpPost(paramss[0]); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); result = false; } Log.d(TAG, "upload finish"); return result; } }; asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug"); asyncTask.isCancelled(); } }); layout.addView(btn8); Button btn9 = new Button(this); btn9.setText("call checkAPK"); btn9.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean result = DefaultCheckerAPK.checkAPK(ExceptionHandlerReportApp.this, null); Log.i(TAG, "checkAPK result=" + result); } }); layout.addView(btn9); setContentView(layout); }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private TextView createTitle(String text) { TextView ret = new TextView(mContext); LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); ret.setLayoutParams(params);/*from w w w.j a v a2 s . c o m*/ ret.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17); ret.setTextColor(Color.BLACK); ret.setText(text); return ret; }
From source file:reportsas.com.formulapp.Formulario.java
public LinearLayout obtenerLayout(LayoutInflater infla, Pregunta preg) { int id;//from ww w .j ava 2s. com int tipo_pregunta = preg.getTipoPregunta(); LinearLayout pregunta; TextView textView; TextView textAyuda; switch (tipo_pregunta) { case 1: id = R.layout.pregunta_texto; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloPregunta); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); break; case 2: id = R.layout.pregunta_multitexto; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.mtxtTritulo); textAyuda = (TextView) pregunta.findViewById(R.id.mtxtAyuda); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); break; case 3: id = R.layout.pregunta_seleccion; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloSeleccion); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_seleccion); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); RadioGroup rg = (RadioGroup) pregunta.findViewById(R.id.opcionesUnica); ArrayList<OpcionForm> opciones = preg.getOpciones(); final ArrayList<RadioButton> rb = new ArrayList<RadioButton>(); for (int i = 0; i < opciones.size(); i++) { OpcionForm opcion = opciones.get(i); rb.add(new RadioButton(this)); rg.addView(rb.get(i)); rb.get(i).setText(opcion.getEtInicial()); } final TextView respt = (TextView) pregunta.findViewById(R.id.respuestaGruop); rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int radioButtonID = group.getCheckedRadioButtonId(); RadioButton radioButton = (RadioButton) group.findViewById(radioButtonID); respt.setText(radioButton.getText()); } }); break; case 4: id = R.layout.pregunta_multiple; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloMultiple); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); ArrayList<OpcionForm> opciones2 = preg.getOpciones(); final EditText ediOtros = new EditText(this); ArrayList<CheckBox> cb = new ArrayList<CheckBox>(); for (int i = 0; i < opciones2.size(); i++) { OpcionForm opcion = opciones2.get(i); cb.add(new CheckBox(this)); pregunta.addView(cb.get(i)); cb.get(i).setText(opcion.getEtInicial()); if (opcion.getEditble().equals("S")) { ediOtros.setEnabled(false); ediOtros.setId(R.id.edtTexto); pregunta.addView(ediOtros); cb.get(i).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ediOtros.setEnabled(true); } else { ediOtros.setText(""); ediOtros.setEnabled(false); } } }); } } TextView spacio = new TextView(this); spacio.setText(" "); spacio.setVisibility(View.INVISIBLE); pregunta.addView(spacio); break; case 5: id = R.layout.pregunta_escala; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloEscala); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_escala); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); TextView etInicial = (TextView) pregunta.findViewById(R.id.etInicial); TextView etFinal = (TextView) pregunta.findViewById(R.id.etFinal); OpcionForm opci = preg.getOpciones().get(0); etInicial.setText(opci.getEtInicial()); etFinal.setText(opci.getEtFinal()); final TextView respEscala = (TextView) pregunta.findViewById(R.id.seleEscala); RatingBar rtBar = (RatingBar) pregunta.findViewById(R.id.escala); rtBar.setNumStars(Integer.parseInt(opci.getValores().get(0).getDescripcion())); rtBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { respEscala.setText("" + Math.round(rating)); } }); break; case 6: id = R.layout.pregunta_lista; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloLista); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_lista); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); ArrayList<OpcionForm> opciones3 = preg.getOpciones(); //Creamos la lista LinkedList<ObjetoSpinner> opcn = new LinkedList<ObjetoSpinner>(); //La poblamos con los ejemplos for (int i = 0; i < opciones3.size(); i++) { opcn.add(new ObjetoSpinner(opciones3.get(i).getIdOpcion(), opciones3.get(i).getEtInicial())); } //Creamos el adaptador*/ Spinner listad = (Spinner) pregunta.findViewById(R.id.opcionesListado); ArrayAdapter<ObjetoSpinner> spinner_adapter = new ArrayAdapter<ObjetoSpinner>(this, android.R.layout.simple_spinner_item, opcn); //Aadimos el layout para el men y se lo damos al spinner spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); listad.setAdapter(spinner_adapter); break; case 7: id = R.layout.pregunta_tabla; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloTabla); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_tabla); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); TableLayout tba = (TableLayout) pregunta.findViewById(R.id.tablaOpciones); ArrayList<OpcionForm> opciones4 = preg.getOpciones(); ArrayList<RadioButton> radiosbotonoes = new ArrayList<RadioButton>(); for (int i = 0; i < opciones4.size(); i++) { TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.row_pregunta_tabla, null); RadioGroup tg_valores = (RadioGroup) row.findViewById(R.id.valoresRow); final ArrayList<RadioButton> valoOpc = new ArrayList<RadioButton>(); ArrayList<Valor> valoresT = opciones4.get(i).getValores(); for (int k = 0; k < valoresT.size(); k++) { RadioButton rb_nuevo = new RadioButton(this); rb_nuevo.setText(valoresT.get(k).getDescripcion()); tg_valores.addView(rb_nuevo); valoOpc.add(rb_nuevo); } ((TextView) row.findViewById(R.id.textoRow)).setText(opciones4.get(i).getEtInicial()); tba.addView(row); } TextView espacio = new TextView(this); espacio.setText(" "); pregunta.addView(espacio); break; case 8: id = R.layout.pregunta_fecha; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloFecha); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_fecha); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); break; case 9: id = R.layout.pregunta_hora; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloHora); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_hora); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); break; default: id = R.layout.pregunta_multiple; pregunta = (LinearLayout) infla.inflate(id, null, false); textView = (TextView) pregunta.findViewById(R.id.TituloMultiple); textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple); textView.setText(preg.getOrden() + ". " + preg.getTitulo()); textAyuda.setText(preg.getTxtAyuda()); break; } return pregunta; }
From source file:com.androprogrammer.tutorials.customviews.SlidingTabLayout.java
protected TextView createDefaultTextTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); }/* w w w . jav a 2 s. c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); //System.out.println("c " + titleColor); if (titleColor != null) { textView.setTextColor(titleColor); } return textView; }
From source file:com.app.plugins.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject //from w w w .ja va2s . co m */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", false); } final WebView parent = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen); 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", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); //LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(cordova.getActivity()); toolbar.setOrientation(LinearLayout.HORIZONTAL); /* ImageButton back = new ImageButton((Context) ctx); back.getBackground().setAlpha(0); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton((Context) ctx); forward.getBackground().setAlpha(0); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); */ /* edittext = new EditText((Context) ctx); 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; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); */ //edittext = new EditText((Context) ctx); //edittext.setVisibility(View.GONE); LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1.0f); TextView title = new TextView(cordova.getActivity()); title.setId(1); title.setLayoutParams(titleParams); title.setGravity(Gravity.CENTER_VERTICAL); title.setTypeface(null, Typeface.BOLD); ImageButton close = new ImageButton(cordova.getActivity()); close.getBackground().setAlpha(0); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("plugins/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); childWebView = new WebView(cordova.getActivity()); childWebView.getSettings().setJavaScriptEnabled(true); childWebView.getSettings().setBuiltInZoomControls(true); WebViewClient client = new ChildBrowserClient(parent, ctx, title/*, edittext*/); childWebView.setWebViewClient(client); childWebView.loadUrl(url); childWebView.setId(5); childWebView.setInitialScale(0); childWebView.setLayoutParams(wvParams); childWebView.requestFocus(); childWebView.requestFocusFromTouch(); //toolbar.addView(back); //toolbar.addView(forward); //toolbar.addView(edittext); toolbar.addView(close); toolbar.addView(title); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(childWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; lp.verticalMargin = 0f; lp.horizontalMargin = 0f; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.crossconnect.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup();// ww w. ja v a 2s. co m mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider); mViewPager = (ViewPager) findViewById(R.id.pager); mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager); //Add top menu icons into the seperate list resource_top_icons = new ArrayList<ImageButton>(); resource_top_icons.add((ImageButton) findViewById(R.id.menu_button_churches)); resource_top_icons.add((ImageButton) findViewById(R.id.menu_button_browse_resources)); bible_text_top_icons = new ArrayList<ImageButton>(); bible_text_top_icons.add((ImageButton) findViewById(R.id.menu_button_tabs)); bible_text_top_icons.add((ImageButton) findViewById(R.id.menu_button_windows)); audio_top_icons = new ArrayList<ImageButton>(); audio_top_icons.add((ImageButton) findViewById(R.id.menu_button_audio)); // audio_top_icons.add((ImageButton) findViewById(R.id.menu_button_browse_audio)); notes_top_icons = new ArrayList<ImageButton>(); notes_top_icons.add((ImageButton) findViewById(R.id.menu_button_notes)); notes_top_icons.add((ImageButton) findViewById(R.id.menu_button_notes_lock)); hideAllIcons(); //Load last opened verse bibleText = Utils.loadBibleText(getSharedPreferences("APP SETTINGS", Context.MODE_PRIVATE)); //Setup listeners for top menu icons //Go to notes browsing view ((ImageButton) findViewById(R.id.menu_button_notes)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, NotesActivity.class); intent.putExtra("Translation", bibleText.getTranslation().getInitials()); startActivityForResult(intent, NOTES_SELECT_CODE); } }); ((ImageButton) findViewById(R.id.menu_button_churches)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, ResourceRepositoryActivity.class); startActivity(intent); } }); // ((ImageButton) findViewById(R.id.menu_button_browse_audio)).setOnClickListener(new OnClickListener(){ // @Override // public void onClick(View v) { // Intent intent = new Intent(MainActivity.this, ResourceRepositoryActivity.class); // startActivity(intent); // } // }); ((ImageButton) findViewById(R.id.menu_button_audio)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, MusicActivity.class); intent.putExtra("Book", bibleText.getBook()); intent.putExtra("Chapter", bibleText.getChapter()); intent.putExtra("Translation", bibleText.getTranslation().getInitials()); startActivity(intent); } }); ((ImageButton) findViewById(R.id.menu_button_browse_resources)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, MusicActivity.class); intent.putExtra("Book", bibleText.getBook()); intent.putExtra("Chapter", bibleText.getChapter()); intent.putExtra("Translation", bibleText.getTranslation().getInitials()); startActivity(intent); } }); headerTitleText = (Button) findViewById(R.id.header_title); headerTitleText.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/" + "Ubuntu-R.ttf"), Typeface.NORMAL); headerTitleText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Editor editor = getSharedPreferences("APP SETTINGS", Context.MODE_PRIVATE).edit(); editor.putString(SharedPreferencesHelper.CURRENT_TAB, mTabHost.getCurrentTabTag()); editor.commit(); //TODO: can we pass the actual BibleText? Intent intent = new Intent(MainActivity.this, ChapterSelectionActivity.class); intent.putExtra("Book", bibleText.getBook()); intent.putExtra("Chapter", bibleText.getChapter()); intent.putExtra("Translation", bibleText.getTranslation().getInitials()); startActivityForResult(intent, CHAPTER_SELECT_CODE); } }); final ActionItem settingsAction = new ActionItem(); settingsAction.setTitle("Settings"); settingsAction.setIcon(getResources().getDrawable(R.drawable.ic_sysbar_quicksettings)); final ActionItem accAction = new ActionItem(); accAction.setTitle("Share"); accAction.setIcon(getResources().getDrawable(R.drawable.kontak)); final ActionItem upAction = new ActionItem(); upAction.setTitle("Star"); upAction.setIcon(getResources().getDrawable(R.drawable.kontak)); findViewById(R.id.title_bar_icon).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mQuickAction = new QuickActionHorizontal(findViewById(R.id.title_bar_icon)); final String text; settingsAction.setOnClickListener(new OnClickListener() { //Copy text action item @Override public void onClick(View v) { startActivityForResult(new Intent(MainActivity.this, PreferencesFromXml.class), SETTINGS_CODE); mQuickAction.dismiss(); } }); accAction.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mQuickAction.dismiss(); } }); upAction.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mQuickAction.dismiss(); } }); mQuickAction.addActionItem(settingsAction); mQuickAction.addActionItem(accAction); mQuickAction.addActionItem(upAction); mQuickAction.setAnimStyle(QuickActionVertical.ANIM_AUTO); mQuickAction.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { } }); mQuickAction.show(); } }); // if (Build.VERSION.SDK_INT >= HONEYCOMB) { // // If has holo theme use holo themed buttons // mTabsAdapter.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"), NoteManagerBibleNotesFragment.class, null); // mTabsAdapter.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"), BookmanagerBibleFragment.class, null); // mTabsAdapter.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"), // LoaderCursorSupport.CursorLoaderListFragment.class, null); // mTabsAdapter.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"), LoaderCustomSupport.AppListFragment.class, null); // mTabsAdapter.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"), // LoaderThrottleSupport.ThrottledLoaderListFragment.class, null); // } else { // Use custom tab style setupTab(new TextView(this), AUDIO_TAG, R.drawable.ico_audio, AudioBibleFragment.class); setupTab(new TextView(this), BIBLE_TAG, R.drawable.ico_bible, BibleTextFragment.class); setupTab(new TextView(this), NOTES_TAG, R.drawable.ico_notes, NotesEditorFragment.class); setupTab(new TextView(this), RESOURCE_TAG, R.drawable.ic_action_microphone, ResourceFragment.class); // setupTab(new TextView(this), "Tab 3", LoaderCustomSupport.AppListFragment.class); // setupTab(new TextView(this), "Tab 4", LoaderThrottleSupport.ThrottledLoaderListFragment.class); // } //Set starting tab if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString(DEFAULT_TAB)); } else { mTabHost.setCurrentTabByTag(BIBLE_TAG); } }
From source file:com.astuetz.PagerSlidingTabStripPlus.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);//from ww w . j a va2 s .c o m tab.setGravity(tabsGravity); tab.setSingleLine(); addTab(position, tab); }