Skip to content

Instantly share code, notes, and snippets.

@aznoisib
Last active June 18, 2020 23:50
Show Gist options
  • Save aznoisib/7082e737f2cbe6b37fe24a13295fbd40 to your computer and use it in GitHub Desktop.
Save aznoisib/7082e737f2cbe6b37fe24a13295fbd40 to your computer and use it in GitHub Desktop.
Drivepad Browser android
package id.cybercode.drivepadbrowser;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.preference.PreferenceDialogFragmentCompat;
import java.text.DecimalFormat;
public class brightnessPreferenceFragmentCompat extends PreferenceDialogFragmentCompat {
private SeekBar mBar;
private CheckBox mCheckBox;
private TextView mMessageText;
public static boolean autoBrightness = true;
public static boolean initialBrightness = true;
public final static int MAXIMUM = 255;
/** Which button was clicked. */
private int mWhichButtonClicked;
public static brightnessPreferenceFragmentCompat newInstance(String key) {
final brightnessPreferenceFragmentCompat fragment = new brightnessPreferenceFragmentCompat();
final Bundle bundle = new Bundle(1);
bundle.putString(ARG_KEY, key);
fragment.setArguments(bundle);
return fragment;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
final SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
final int curBrightnessValue = android.provider.Settings.System.getInt(getActivity().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS,-1);
Log.v("kapok",String.valueOf(getSeekBarPreference().getProgress()/MAXIMUM));
mBar = view.findViewById(R.id.slider_preference_seekbar);
mMessageText = view.findViewById(R.id.persentase);
mCheckBox = view.findViewById(R.id.checkbox);
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(compoundButton.isChecked()){
autoBrightness = true;
System.out.println("Current Brightness level " + curBrightnessValue);
mBar.setProgress(curBrightnessValue);
//editor.putBoolean("ness",true);
// editor.apply();
}else{
autoBrightness = false;
//SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
//SharedPreferences.Editor editor = Brightsettings.edit(); //2
//editor.putBoolean("ness",false);
//editor.apply();
}
}
});
mBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@SuppressLint("SetTextI18n")
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
WindowManager.LayoutParams layoutParams =getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = i / (float)255; // Set Value
//layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams); // Set params
float proportion = ((float) i) / ((float) MAXIMUM);
DecimalFormat df = new DecimalFormat("#");
mMessageText.setText(df.format(proportion*100) + "%");
Log.v("kapok",df.format(proportion*100));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.v("kapoks","ok");
if(mCheckBox.isChecked()) mCheckBox.setChecked(false);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
if(!initialBrightness){
mCheckBox.setChecked(Brightsettings.getBoolean("ness", false));
mBar.setProgress(Brightsettings.getBoolean("ness",false) ? curBrightnessValue : getSeekBarPreference().getProgress());
}else{
mCheckBox.setChecked(true);
mBar.setProgress(curBrightnessValue);
}
mBar.setMax(MAXIMUM);
}
//@Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//mSeekBarValue = (int) (mValue * SEEKBAR_RESOLUTION);
//final View customView = getLayoutInflater().inflate(R.layout.sliderl, null);
// mBar.setProgress(55);
// mBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
// @Override
// public void onStopTrackingTouch(SeekBar seekBar) {
// }
// @Override
//public void onStartTrackingTouch(SeekBar seekBar) {
//}
// @Override
// public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//Log.v("kapok", String.valueOf(progress));
// if (fromUser) {
//SliderPreference.this.mSeekBarValue = progress;
//}
// }
// });
// return customView;
//}
@Override
public void onDialogClosed(boolean positiveResult) {
final SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = Brightsettings.edit(); //2
if (positiveResult) {
initialBrightness = false;
if(autoBrightness){
editor.putBoolean("ness",true);
editor.apply();
}else{
editor.putBoolean("ness",false);
editor.apply();
}
if(Brightsettings.getBoolean("ness",false)){
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams);
}
//mBar.getProgress()
int value = mBar.getProgress();
brightnessBarPreference preference = getSeekBarPreference();
if (preference.callChangeListener(value)) {
Log.v("kapok", String.valueOf(value));
preference.setProgress(value);
}
}else{
//((Activity) getContext())
// WindowManager.LayoutParams layoutParams =getActivity().getWindow().getAttributes(); // Get Params
// layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
// getActivity().getWindow().setAttributes(layoutParams); // Set params
//}else{
//if(Brightsettings.getBoolean("ness",false)){
//global.setScreenBrightness(((Activity) getContext()).getWindow(),getSeekBarPreference().getProgress());
// global.setScreenBrightness(((Activity) getContext()).getWindow(),android.provider.Settings.System.getInt(getActivity().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS,-1));
//}
//if(autoBrightness) {
if(!Brightsettings.getBoolean("ness",false)) {
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = getSeekBarPreference().getProgress() / (float) 255;
getActivity().getWindow().setAttributes(layoutParams);
}else{
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams);
}
//WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
//layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
//getActivity().getWindow().setAttributes(layoutParams);
}
}
private brightnessBarPreference getSeekBarPreference() {
return (brightnessBarPreference) getPreference();
}
}
package id.cybercode.drivepadbrowser;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.preference.PreferenceDialogFragmentCompat;
import java.text.DecimalFormat;
public class brightnessPreferenceFragmentCompat extends PreferenceDialogFragmentCompat {
private SeekBar mBar;
private CheckBox mCheckBox;
private TextView mMessageText;
public static boolean autoBrightness = true;
public static boolean initialBrightness = true;
public final static int MAXIMUM = 255;
/** Which button was clicked. */
private int mWhichButtonClicked;
public static brightnessPreferenceFragmentCompat newInstance(String key) {
final brightnessPreferenceFragmentCompat fragment = new brightnessPreferenceFragmentCompat();
final Bundle bundle = new Bundle(1);
bundle.putString(ARG_KEY, key);
fragment.setArguments(bundle);
return fragment;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
final SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
final int curBrightnessValue = android.provider.Settings.System.getInt(getActivity().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS,-1);
Log.v("kapok",String.valueOf(getSeekBarPreference().getProgress()/MAXIMUM));
mBar = view.findViewById(R.id.slider_preference_seekbar);
mMessageText = view.findViewById(R.id.persentase);
mCheckBox = view.findViewById(R.id.checkbox);
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(compoundButton.isChecked()){
autoBrightness = true;
System.out.println("Current Brightness level " + curBrightnessValue);
mBar.setProgress(curBrightnessValue);
//editor.putBoolean("ness",true);
// editor.apply();
}else{
autoBrightness = false;
//SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
//SharedPreferences.Editor editor = Brightsettings.edit(); //2
//editor.putBoolean("ness",false);
//editor.apply();
}
}
});
mBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@SuppressLint("SetTextI18n")
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
WindowManager.LayoutParams layoutParams =getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = i / (float)255; // Set Value
//layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams); // Set params
float proportion = ((float) i) / ((float) MAXIMUM);
DecimalFormat df = new DecimalFormat("#");
mMessageText.setText(df.format(proportion*100) + "%");
Log.v("kapok",df.format(proportion*100));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.v("kapoks","ok");
if(mCheckBox.isChecked()) mCheckBox.setChecked(false);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
if(!initialBrightness){
mCheckBox.setChecked(Brightsettings.getBoolean("ness", false));
mBar.setProgress(Brightsettings.getBoolean("ness",false) ? curBrightnessValue : getSeekBarPreference().getProgress());
}else{
mCheckBox.setChecked(true);
mBar.setProgress(curBrightnessValue);
}
mBar.setMax(MAXIMUM);
}
//@Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//mSeekBarValue = (int) (mValue * SEEKBAR_RESOLUTION);
//final View customView = getLayoutInflater().inflate(R.layout.sliderl, null);
// mBar.setProgress(55);
// mBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
// @Override
// public void onStopTrackingTouch(SeekBar seekBar) {
// }
// @Override
//public void onStartTrackingTouch(SeekBar seekBar) {
//}
// @Override
// public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//Log.v("kapok", String.valueOf(progress));
// if (fromUser) {
//SliderPreference.this.mSeekBarValue = progress;
//}
// }
// });
// return customView;
//}
@Override
public void onDialogClosed(boolean positiveResult) {
final SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = Brightsettings.edit(); //2
if (positiveResult) {
initialBrightness = false;
if(autoBrightness){
editor.putBoolean("ness",true);
editor.apply();
}else{
editor.putBoolean("ness",false);
editor.apply();
}
if(Brightsettings.getBoolean("ness",false)){
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams);
}
//mBar.getProgress()
int value = mBar.getProgress();
brightnessBarPreference preference = getSeekBarPreference();
if (preference.callChangeListener(value)) {
Log.v("kapok", String.valueOf(value));
preference.setProgress(value);
}
}else{
//((Activity) getContext())
// WindowManager.LayoutParams layoutParams =getActivity().getWindow().getAttributes(); // Get Params
// layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
// getActivity().getWindow().setAttributes(layoutParams); // Set params
//}else{
//if(Brightsettings.getBoolean("ness",false)){
//global.setScreenBrightness(((Activity) getContext()).getWindow(),getSeekBarPreference().getProgress());
// global.setScreenBrightness(((Activity) getContext()).getWindow(),android.provider.Settings.System.getInt(getActivity().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS,-1));
//}
//if(autoBrightness) {
if(!Brightsettings.getBoolean("ness",false)) {
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = getSeekBarPreference().getProgress() / (float) 255;
getActivity().getWindow().setAttributes(layoutParams);
}else{
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams);
}
//WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
//layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
//getActivity().getWindow().setAttributes(layoutParams);
}
}
private brightnessBarPreference getSeekBarPreference() {
return (brightnessBarPreference) getPreference();
}
}
package id.cybercode.drivepadbrowser3;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Process;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.Patterns;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private ImageButton bMark;
private Toast backtoast;
private View child;
private int currentTabIndex;
private Activity mActivity;
private CoordinatorLayout mCLayout;
private Context mContext;
private EditText mEditText;
private ProgressBar mProgressBar;
private Rect mRect = new Rect();
private TextView mTxtabcount;
private ArrayList<Tab> tabs = new ArrayList();
private EditText txturl;
private WebView webpad;
private FrameLayout webpads;
private RelativeLayout webrelative;
static class ArrayAdapterWithCurrentItem<T> extends ArrayAdapter<T> {
int currentIndex;
ArrayAdapterWithCurrentItem(Context context, int resource, T[] objects, int currentIndex) {
super(context, resource, objects);
this.currentIndex = currentIndex;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(16908308);
Drawable d = getContext().getResources().getDrawable(position == this.currentIndex ? R.drawable.ic_open_in_browser_black_24dp : R.drawable.empty, null);
int size = (int) TypedValue.applyDimension(1, 24.0f, getContext().getResources().getDisplayMetrics());
d.setBounds(0, 0, size, size);
textView.setCompoundDrawablesRelative(d, null, null, null);
textView.setCompoundDrawablePadding((int) TypedValue.applyDimension(1, 12.0f, getContext().getResources().getDisplayMetrics()));
return view;
}
}
private static class Tab {
WebView webview;
Tab(WebView w) {
this.webview = w;
}
}
private Tab getCurrentTab() {
return (Tab) this.tabs.get(this.currentTabIndex);
}
private WebView getCurrentWebView() {
return getCurrentTab().webview;
}
private void loadWebview(String url, WebView webview) {
url = url.trim();
String guess = URLUtil.guessUrl(url);
if (url.toLowerCase().contains("http://") || url.toLowerCase().contains("https://") || !Patterns.WEB_URL.matcher(url).matches()) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("https://www.google.com/search?q=");
stringBuilder.append(url);
url = stringBuilder.toString();
} else {
url = guess;
}
webview.loadUrl(url);
}
private void showOpenTabs() {
String[] items = new String[this.tabs.size()];
for (int i = 0; i < this.tabs.size(); i++) {
items[i] = ((Tab) this.tabs.get(i)).webview.getTitle();
}
new Builder(this).setTitle("Tabs").setAdapter(new ArrayAdapterWithCurrentItem(this, 17367043, items, this.currentTabIndex), new -$$Lambda$MainActivity$4yeqPVgdZBYYduka752TdeemtnA(this)).show();
}
public /* synthetic */ void lambda$showOpenTabs$0$MainActivity(DialogInterface dialog, int which) {
switchToTab(which);
}
private void switchToTab(int tab) {
getCurrentWebView().setVisibility(8);
this.currentTabIndex = tab;
getCurrentWebView().setVisibility(0);
getCurrentWebView().requestFocus();
}
private void newTab(String url) {
WebView webview = createWebView();
this.webrelative = (RelativeLayout) findViewById(R.id.rlayout);
webview.setLayoutParams(this.webpad.getLayoutParams());
webview.setVisibility(8);
this.tabs.add(new Tab(webview));
this.webpad.addView(webview);
this.mTxtabcount.setText(String.valueOf(this.tabs.size()));
loadWebview(url, webview);
}
private void closeCurrentTab() {
((WebView) findViewById(R.id.webpad)).removeView(getCurrentWebView());
getCurrentWebView().destroy();
this.tabs.remove(this.currentTabIndex);
if (this.currentTabIndex >= this.tabs.size()) {
this.currentTabIndex = this.tabs.size() - 1;
}
if (this.currentTabIndex == -1) {
newTab(BuildConfig.FLAVOR);
this.currentTabIndex = 0;
}
getCurrentWebView().setVisibility(0);
this.mTxtabcount.setText(String.valueOf(this.tabs.size()));
getCurrentWebView().requestFocus();
}
private WebView createWebView() {
WebView webview = new WebView(this);
WebSettings settings = webview.getSettings();
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress == 100) {
MainActivity.this.mProgressBar.setVisibility(8);
} else {
MainActivity.this.mProgressBar.setProgress(newProgress);
}
}
});
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String url_new = view.getUrl();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Webview Function URL: ");
stringBuilder.append(url_new);
Log.v(BuildConfig.FLAVOR, stringBuilder.toString());
if (view == MainActivity.this.getCurrentWebView()) {
MainActivity.this.mEditText.setText(view.getUrl());
}
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
String url_new = view.getUrl();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Webview Function URL: ");
stringBuilder.append(url_new);
Log.v(BuildConfig.FLAVOR, stringBuilder.toString());
MainActivity.this.mProgressBar.setProgress(0);
MainActivity.this.mProgressBar.setVisibility(0);
if (view == MainActivity.this.getCurrentWebView()) {
MainActivity.this.mEditText.setText(url);
}
}
});
return webview;
}
/* Access modifiers changed, original: protected */
public void startWebPage(String urlToRender) {
this.webpad.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress == 100) {
MainActivity.this.mProgressBar.setVisibility(8);
} else {
MainActivity.this.mProgressBar.setProgress(newProgress);
}
}
});
this.webpad.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String url_new = view.getUrl();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Webview Function URL: ");
stringBuilder.append(url_new);
Log.v(BuildConfig.FLAVOR, stringBuilder.toString());
MainActivity.this.mEditText.setText(url_new);
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
String url_new = view.getUrl();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Webview Function URL: ");
stringBuilder.append(url_new);
Log.v(BuildConfig.FLAVOR, stringBuilder.toString());
MainActivity.this.mEditText.setText(url_new);
MainActivity.this.mProgressBar.setProgress(0);
MainActivity.this.mProgressBar.setVisibility(0);
}
});
this.webpad.getSettings().setJavaScriptEnabled(true);
this.webpad.loadUrl(urlToRender);
}
/* Access modifiers changed, original: protected */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
this.webpad = (WebView) findViewById(R.id.webpad);
this.mContext = getApplicationContext();
this.mActivity = this;
this.mCLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
this.mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
this.mEditText = (EditText) findViewById(R.id.et);
this.mTxtabcount = (TextView) findViewById(R.id.ex);
if (this.currentTabIndex >= this.tabs.size()) {
this.currentTabIndex = this.tabs.size() - 1;
}
if (this.currentTabIndex == -1) {
newTab("https://yahoo.com");
this.currentTabIndex = 0;
}
getCurrentWebView().setVisibility(0);
this.mTxtabcount.setText(String.valueOf(this.tabs.size()));
getCurrentWebView().requestFocus();
this.mEditText.setOnKeyListener(new -$$Lambda$MainActivity$v8fOt9_1279E1LbQnePbJiSB-7Q(this));
this.mEditText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
String GG = String.valueOf(i);
if (i != 2) {
return false;
}
((InputMethodManager) MainActivity.this.mContext.getSystemService("input_method")).hideSoftInputFromWindow(MainActivity.this.mEditText.getWindowToken(), 0);
WebView access$400 = MainActivity.this.webpad;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("https://www.google.com/search?q=");
stringBuilder.append(MainActivity.this.mEditText.getText().toString());
access$400.loadUrl(stringBuilder.toString());
return true;
}
});
}
public /* synthetic */ boolean lambda$onCreate$1$MainActivity(View v, int keyCode, KeyEvent event) {
if (event.getAction() != 0 || keyCode != 66) {
return false;
}
loadWebview(this.mEditText.getText().toString(), getCurrentWebView());
getCurrentWebView().requestFocus();
return true;
}
public void onBackPressed() {
if (getCurrentWebView().canGoBack()) {
getCurrentWebView().goBack();
} else if (this.tabs.size() > 1) {
closeCurrentTab();
} else {
super.onBackPressed();
}
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
Menu bottomMenu = ((ActionMenuView) findViewById(R.id.bottom_toolbar)).getMenu();
getMenuInflater().inflate(R.menu.bottom_menu, bottomMenu);
for (int i = 0; i < bottomMenu.size(); i++) {
bottomMenu.getItem(i).setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return MainActivity.this.onOptionsItemSelected(item);
}
});
}
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
String str = "Action";
String str2 = "Replace with your own action";
if (id == R.id.action_settings) {
Snackbar.make(this.mCLayout, str2, 0).setAction(str, null).show();
return true;
} else if (id == R.id.action_refresh) {
Process.killProcess(Process.myPid());
System.exit(0);
getParent().finish();
Snackbar.make(this.mCLayout, str2, 0).setAction(str, null).show();
return true;
} else if (id == R.id.action_addTab) {
newTab("http://google.com");
switchToTab(this.tabs.size() - 1);
return true;
} else if (id == R.id.action_showTab) {
showOpenTabs();
return true;
} else if (id != R.id.action_closecurrentab) {
return super.onOptionsItemSelected(item);
} else {
closeCurrentTab();
return true;
}
}
}
package id.cybercode.drivepadbrowser;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.preference.PreferenceDialogFragmentCompat;
import java.text.DecimalFormat;
public class brightnessPreferenceFragmentCompat extends PreferenceDialogFragmentCompat {
private SeekBar mBar;
private CheckBox mCheckBox;
private TextView mMessageText;
public static boolean autoBrightness = true;
public static boolean initialBrightness = true;
public final static int MAXIMUM = 255;
/** Which button was clicked. */
private int mWhichButtonClicked;
public static brightnessPreferenceFragmentCompat newInstance(String key) {
final brightnessPreferenceFragmentCompat fragment = new brightnessPreferenceFragmentCompat();
final Bundle bundle = new Bundle(1);
bundle.putString(ARG_KEY, key);
fragment.setArguments(bundle);
return fragment;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
final SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
final int curBrightnessValue = android.provider.Settings.System.getInt(getActivity().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS,-1);
Log.v("kapok",String.valueOf(getSeekBarPreference().getProgress()/MAXIMUM));
mBar = view.findViewById(R.id.slider_preference_seekbar);
mMessageText = view.findViewById(R.id.persentase);
mCheckBox = view.findViewById(R.id.checkbox);
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(compoundButton.isChecked()){
autoBrightness = true;
System.out.println("Current Brightness level " + curBrightnessValue);
mBar.setProgress(curBrightnessValue);
//editor.putBoolean("ness",true);
// editor.apply();
}else{
autoBrightness = false;
//SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
//SharedPreferences.Editor editor = Brightsettings.edit(); //2
//editor.putBoolean("ness",false);
//editor.apply();
}
}
});
mBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@SuppressLint("SetTextI18n")
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
WindowManager.LayoutParams layoutParams =getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = i / (float)255; // Set Value
//layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams); // Set params
float proportion = ((float) i) / ((float) MAXIMUM);
DecimalFormat df = new DecimalFormat("#");
mMessageText.setText(df.format(proportion*100) + "%");
Log.v("kapok",df.format(proportion*100));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.v("kapoks","ok");
if(mCheckBox.isChecked()) mCheckBox.setChecked(false);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
if(!initialBrightness){
mCheckBox.setChecked(Brightsettings.getBoolean("ness", false));
mBar.setProgress(Brightsettings.getBoolean("ness",false) ? curBrightnessValue : getSeekBarPreference().getProgress());
}else{
mCheckBox.setChecked(true);
mBar.setProgress(curBrightnessValue);
}
mBar.setMax(MAXIMUM);
}
//@Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//mSeekBarValue = (int) (mValue * SEEKBAR_RESOLUTION);
//final View customView = getLayoutInflater().inflate(R.layout.sliderl, null);
// mBar.setProgress(55);
// mBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
// @Override
// public void onStopTrackingTouch(SeekBar seekBar) {
// }
// @Override
//public void onStartTrackingTouch(SeekBar seekBar) {
//}
// @Override
// public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//Log.v("kapok", String.valueOf(progress));
// if (fromUser) {
//SliderPreference.this.mSeekBarValue = progress;
//}
// }
// });
// return customView;
//}
@Override
public void onDialogClosed(boolean positiveResult) {
final SharedPreferences Brightsettings = getContext().getSharedPreferences("brightness", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = Brightsettings.edit(); //2
if (positiveResult) {
initialBrightness = false;
if(autoBrightness){
editor.putBoolean("ness",true);
editor.apply();
}else{
editor.putBoolean("ness",false);
editor.apply();
}
if(Brightsettings.getBoolean("ness",false)){
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams);
}
//mBar.getProgress()
int value = mBar.getProgress();
brightnessBarPreference preference = getSeekBarPreference();
if (preference.callChangeListener(value)) {
Log.v("kapok", String.valueOf(value));
preference.setProgress(value);
}
}else{
//((Activity) getContext())
// WindowManager.LayoutParams layoutParams =getActivity().getWindow().getAttributes(); // Get Params
// layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
// getActivity().getWindow().setAttributes(layoutParams); // Set params
//}else{
//if(Brightsettings.getBoolean("ness",false)){
//global.setScreenBrightness(((Activity) getContext()).getWindow(),getSeekBarPreference().getProgress());
// global.setScreenBrightness(((Activity) getContext()).getWindow(),android.provider.Settings.System.getInt(getActivity().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS,-1));
//}
//if(autoBrightness) {
if(!Brightsettings.getBoolean("ness",false)) {
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = getSeekBarPreference().getProgress() / (float) 255;
getActivity().getWindow().setAttributes(layoutParams);
}else{
WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
getActivity().getWindow().setAttributes(layoutParams);
}
//WindowManager.LayoutParams layoutParams = getActivity().getWindow().getAttributes(); // Get Params
//layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
//getActivity().getWindow().setAttributes(layoutParams);
}
}
private brightnessBarPreference getSeekBarPreference() {
return (brightnessBarPreference) getPreference();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment