use of android.widget.ProgressBar in project SmartAndroidSource by jaychou2012.
the class Common method showProgress.
public static void showProgress(Object p, String url, boolean show) {
if (p != null) {
if (p instanceof View) {
View pv = (View) p;
ProgressBar pbar = null;
if (p instanceof ProgressBar) {
pbar = (ProgressBar) p;
}
if (show) {
pv.setTag(AQuery.TAG_URL, url);
pv.setVisibility(View.VISIBLE);
if (pbar != null) {
pbar.setProgress(0);
pbar.setMax(100);
}
} else {
Object tag = pv.getTag(AQuery.TAG_URL);
if (tag == null || tag.equals(url)) {
pv.setTag(AQuery.TAG_URL, null);
if (pbar == null || pbar.isIndeterminate()) {
pv.setVisibility(View.GONE);
}
}
}
} else if (p instanceof Dialog) {
Dialog pd = (Dialog) p;
AQuery aq = new AQuery(pd.getContext());
if (show) {
aq.show(pd);
} else {
aq.dismiss(pd);
}
} else if (p instanceof Activity) {
Activity act = (Activity) p;
;
act.setProgressBarIndeterminateVisibility(show);
act.setProgressBarVisibility(show);
if (show) {
act.setProgress(0);
}
}
}
}
use of android.widget.ProgressBar in project ViewPagerIndicator by LuckyJayce.
the class YearFragment method onCreateViewLazy.
@Override
protected void onCreateViewLazy(Bundle savedInstanceState) {
super.onCreateViewLazy(savedInstanceState);
Log.d("pppp", "onCreateViewLazy " + this + " " + savedInstanceState);
int position = getArguments().getInt(INTENT_INT_POSITION);
setContentView(R.layout.fragment_tabmain_item);
final TextView textView = (TextView) findViewById(R.id.fragment_mainTab_item_textView);
textView.setText(" " + position + " 界面加载完毕");
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.fragment_mainTab_item_progressBar);
textView.postDelayed(new Runnable() {
@Override
public void run() {
textView.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
}, 3000);
}
use of android.widget.ProgressBar in project XPrivacy by M66B.
the class PrivacyService method getOnDemandView.
@SuppressLint("InflateParams")
private View getOnDemandView(final PRestriction restriction, final Hook hook, ApplicationInfoEx appInfo, final PRestriction result, Context context, final OnDemandDialogHolder holder, final OnDemandResult oResult) throws NameNotFoundException, RemoteException {
// Get resources
String self = PrivacyService.class.getPackage().getName();
Resources resources = context.getPackageManager().getResourcesForApplication(self);
// Reference views
final View view = LayoutInflater.from(context.createPackageContext(self, 0)).inflate(R.layout.ondemand, null);
ImageView ivAppIcon = (ImageView) view.findViewById(R.id.ivAppIcon);
TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
TextView tvAppName = (TextView) view.findViewById(R.id.tvAppName);
TextView tvCategory = (TextView) view.findViewById(R.id.tvCategory);
TextView tvFunction = (TextView) view.findViewById(R.id.tvFunction);
TextView tvParameters = (TextView) view.findViewById(R.id.tvParameters);
TableRow rowParameters = (TableRow) view.findViewById(R.id.rowParameters);
TextView tvDefault = (TextView) view.findViewById(R.id.tvDefault);
TextView tvInfoCategory = (TextView) view.findViewById(R.id.tvInfoCategory);
final CheckBox cbExpert = (CheckBox) view.findViewById(R.id.cbExpert);
final CheckBox cbCategory = (CheckBox) view.findViewById(R.id.cbCategory);
final CheckBox cbOnce = (CheckBox) view.findViewById(R.id.cbOnce);
final Spinner spOnce = (Spinner) view.findViewById(R.id.spOnce);
final LinearLayout llWhiteList = (LinearLayout) view.findViewById(R.id.llWhiteList);
final CheckBox cbWhitelist = (CheckBox) view.findViewById(R.id.cbWhitelist);
final CheckBox cbWhitelistExtra1 = (CheckBox) view.findViewById(R.id.cbWhitelistExtra1);
final CheckBox cbWhitelistExtra2 = (CheckBox) view.findViewById(R.id.cbWhitelistExtra2);
final CheckBox cbWhitelistExtra3 = (CheckBox) view.findViewById(R.id.cbWhitelistExtra3);
ProgressBar mProgress = (ProgressBar) view.findViewById(R.id.pbProgress);
Button btnDeny = (Button) view.findViewById(R.id.btnDeny);
Button btnDontKnow = (Button) view.findViewById(R.id.btnDontKnow);
Button btnAllow = (Button) view.findViewById(R.id.btnAllow);
final int userId = Util.getUserId(Process.myUid());
boolean expert = getSettingBool(userId, PrivacyManager.cSettingODExpert, false);
boolean category = getSettingBool(userId, PrivacyManager.cSettingODCategory, true);
boolean once = getSettingBool(userId, PrivacyManager.cSettingODOnce, false);
expert = expert || !category || once;
final boolean whitelistDangerous = (hook != null && hook.isDangerous() && hook.whitelist() != null);
// Set values
if ((hook != null && hook.isDangerous()) || appInfo.isSystem())
view.setBackgroundResource(R.color.color_dangerous_dialog);
else
view.setBackgroundResource(android.R.color.background_dark);
// Application information
ivAppIcon.setImageDrawable(appInfo.getIcon(context));
tvUid.setText(Integer.toString(appInfo.getUid()));
tvAppName.setText(TextUtils.join(", ", appInfo.getApplicationName()));
// Restriction information
int catId = resources.getIdentifier("restrict_" + restriction.restrictionName, "string", self);
tvCategory.setText(resources.getString(catId));
tvFunction.setText(restriction.methodName);
if (restriction.extra == null)
rowParameters.setVisibility(View.GONE);
else
tvParameters.setText(restriction.extra);
String defaultAction = resources.getString(result.restricted ? R.string.title_deny : R.string.title_allow);
tvDefault.setText(defaultAction);
// Help
int helpId = resources.getIdentifier("restrict_help_" + restriction.restrictionName, "string", self);
tvInfoCategory.setText(resources.getString(helpId));
// Expert mode
cbExpert.setChecked(expert);
if (expert) {
for (View child : Util.getViewsByTag((ViewGroup) view, "details")) child.setVisibility(View.VISIBLE);
for (View child : Util.getViewsByTag((ViewGroup) view, "nodetails")) child.setVisibility(View.GONE);
}
if (expert || whitelistDangerous)
llWhiteList.setVisibility(View.VISIBLE);
// Category
cbCategory.setChecked(category);
// Once
cbOnce.setChecked(once);
int osel = Integer.parseInt(getSetting(new PSetting(userId, "", PrivacyManager.cSettingODOnceDuration, "0")).value);
spOnce.setSelection(osel);
// Whitelisting
if (hook != null && hook.whitelist() != null && restriction.extra != null) {
cbWhitelist.setText(resources.getString(R.string.title_whitelist, restriction.extra));
cbWhitelist.setVisibility(View.VISIBLE);
String[] xextra = getXExtra(restriction, hook);
if (xextra.length > 0) {
cbWhitelistExtra1.setText(resources.getString(R.string.title_whitelist, xextra[0]));
cbWhitelistExtra1.setVisibility(View.VISIBLE);
}
if (xextra.length > 1) {
cbWhitelistExtra2.setText(resources.getString(R.string.title_whitelist, xextra[1]));
cbWhitelistExtra2.setVisibility(View.VISIBLE);
}
if (xextra.length > 2) {
cbWhitelistExtra3.setText(resources.getString(R.string.title_whitelist, xextra[2]));
cbWhitelistExtra3.setVisibility(View.VISIBLE);
}
}
cbExpert.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
setSettingBool(userId, "", PrivacyManager.cSettingODExpert, isChecked);
if (!isChecked) {
setSettingBool(userId, "", PrivacyManager.cSettingODCategory, true);
setSettingBool(userId, "", PrivacyManager.cSettingODOnce, false);
cbCategory.setChecked(true);
cbOnce.setChecked(false);
cbWhitelist.setChecked(false);
cbWhitelistExtra1.setChecked(false);
cbWhitelistExtra2.setChecked(false);
cbWhitelistExtra3.setChecked(false);
}
for (View child : Util.getViewsByTag((ViewGroup) view, "details")) child.setVisibility(isChecked ? View.VISIBLE : View.GONE);
for (View child : Util.getViewsByTag((ViewGroup) view, "nodetails")) child.setVisibility(isChecked ? View.GONE : View.VISIBLE);
if (!whitelistDangerous)
llWhiteList.setVisibility(isChecked ? View.VISIBLE : View.GONE);
}
});
// Category, once and whitelist exclude each other
cbCategory.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cbWhitelist.setChecked(false);
cbWhitelistExtra1.setChecked(false);
cbWhitelistExtra2.setChecked(false);
cbWhitelistExtra3.setChecked(false);
}
}
});
cbOnce.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cbWhitelist.setChecked(false);
cbWhitelistExtra1.setChecked(false);
cbWhitelistExtra2.setChecked(false);
cbWhitelistExtra3.setChecked(false);
}
}
});
cbWhitelist.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cbCategory.setChecked(false);
cbOnce.setChecked(false);
cbWhitelistExtra1.setChecked(false);
cbWhitelistExtra2.setChecked(false);
cbWhitelistExtra3.setChecked(false);
}
}
});
cbWhitelistExtra1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cbCategory.setChecked(false);
cbOnce.setChecked(false);
cbWhitelist.setChecked(false);
cbWhitelistExtra2.setChecked(false);
cbWhitelistExtra3.setChecked(false);
}
}
});
cbWhitelistExtra2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cbCategory.setChecked(false);
cbOnce.setChecked(false);
cbWhitelist.setChecked(false);
cbWhitelistExtra1.setChecked(false);
cbWhitelistExtra3.setChecked(false);
}
}
});
cbWhitelistExtra3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cbCategory.setChecked(false);
cbOnce.setChecked(false);
cbWhitelist.setChecked(false);
cbWhitelistExtra1.setChecked(false);
cbWhitelistExtra2.setChecked(false);
}
}
});
// Setup progress bar
mProgress.setMax(cMaxOnDemandDialog * 20);
mProgress.setProgress(cMaxOnDemandDialog * 20);
btnAllow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Allow
result.restricted = false;
result.asked = true;
if (cbWhitelist.isChecked())
onDemandWhitelist(restriction, null, result, oResult, hook);
else if (cbWhitelistExtra1.isChecked())
onDemandWhitelist(restriction, getXExtra(restriction, hook)[0], result, oResult, hook);
else if (cbWhitelistExtra2.isChecked())
onDemandWhitelist(restriction, getXExtra(restriction, hook)[1], result, oResult, hook);
else if (cbWhitelistExtra3.isChecked())
onDemandWhitelist(restriction, getXExtra(restriction, hook)[2], result, oResult, hook);
else {
setSettingBool(userId, "", PrivacyManager.cSettingODCategory, cbCategory.isChecked());
setSettingBool(userId, "", PrivacyManager.cSettingODOnce, cbOnce.isChecked());
if (cbOnce.isChecked())
onDemandOnce(restriction, cbCategory.isChecked(), result, oResult, spOnce);
else
onDemandChoice(restriction, cbCategory.isChecked(), false);
}
holder.latch.countDown();
}
});
btnDontKnow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Deny once
result.restricted = !(hook != null && hook.isDangerous());
result.asked = true;
onDemandOnce(restriction, false, result, oResult, spOnce);
holder.latch.countDown();
}
});
btnDeny.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Deny
result.restricted = true;
result.asked = true;
if (cbWhitelist.isChecked())
onDemandWhitelist(restriction, null, result, oResult, hook);
else if (cbWhitelistExtra1.isChecked())
onDemandWhitelist(restriction, getXExtra(restriction, hook)[0], result, oResult, hook);
else if (cbWhitelistExtra2.isChecked())
onDemandWhitelist(restriction, getXExtra(restriction, hook)[1], result, oResult, hook);
else if (cbWhitelistExtra3.isChecked())
onDemandWhitelist(restriction, getXExtra(restriction, hook)[2], result, oResult, hook);
else {
setSettingBool(userId, "", PrivacyManager.cSettingODCategory, cbCategory.isChecked());
setSettingBool(userId, "", PrivacyManager.cSettingODOnce, cbOnce.isChecked());
if (cbOnce.isChecked())
onDemandOnce(restriction, cbCategory.isChecked(), result, oResult, spOnce);
else
onDemandChoice(restriction, cbCategory.isChecked(), true);
}
holder.latch.countDown();
}
});
return view;
}
use of android.widget.ProgressBar in project XPrivacy by M66B.
the class PrivacyService method onDemandDialog.
// Helper methods
private OnDemandResult onDemandDialog(final Hook hook, final PRestriction restriction, final PRestriction result) {
final OnDemandResult oResult = new OnDemandResult();
try {
int userId = Util.getUserId(restriction.uid);
// Check if application
if (!PrivacyManager.isApplication(restriction.uid))
if (!getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false))
return oResult;
// Check for exceptions
if (hook != null && !hook.canOnDemand())
return oResult;
if (!PrivacyManager.canRestrict(restriction.uid, getXUid(), restriction.restrictionName, restriction.methodName, false))
return oResult;
// Check if enabled
if (!getSettingBool(userId, PrivacyManager.cSettingOnDemand, true))
return oResult;
if (!getSettingBool(restriction.uid, PrivacyManager.cSettingOnDemand, false))
return oResult;
// Check version
String version = getSetting(new PSetting(userId, "", PrivacyManager.cSettingVersion, "0.0")).value;
if (new Version(version).compareTo(new Version("2.1.5")) < 0)
return oResult;
// Get activity manager context
final Context context = getContext();
if (context == null)
return oResult;
long token = 0;
try {
token = Binder.clearCallingIdentity();
// Get application info
final ApplicationInfoEx appInfo = new ApplicationInfoEx(context, restriction.uid);
// Check for system application
if (appInfo.isSystem())
if (new Version(version).compareTo(new Version("2.0.38")) < 0)
return oResult;
// Check if activity manager agrees
if (!XActivityManagerService.canOnDemand())
return oResult;
// Check if activity manager locked
if (isAMLocked(restriction.uid)) {
Util.log(null, Log.WARN, "On demand locked " + restriction);
return oResult;
}
// Go ask
Util.log(null, Log.WARN, "On demand " + restriction);
mOndemandSemaphore.acquireUninterruptibly();
try {
// Check if activity manager still agrees
if (!XActivityManagerService.canOnDemand())
return oResult;
// Check if activity manager locked now
if (isAMLocked(restriction.uid)) {
Util.log(null, Log.WARN, "On demand acquired locked " + restriction);
return oResult;
}
Util.log(null, Log.WARN, "On demanding " + restriction);
// Check if method not asked before
CRestriction mkey = new CRestriction(restriction, null);
synchronized (mRestrictionCache) {
if (mRestrictionCache.containsKey(mkey)) {
CRestriction mrestriction = mRestrictionCache.get(mkey);
if (mrestriction.asked) {
Util.log(null, Log.WARN, "Already asked " + restriction);
result.restricted = mrestriction.restricted;
result.asked = true;
return oResult;
}
}
}
// Check if category not asked before (once)
CRestriction ckey = new CRestriction(restriction, null);
ckey.setMethodName(null);
synchronized (mAskedOnceCache) {
if (mAskedOnceCache.containsKey(ckey)) {
CRestriction carestriction = mAskedOnceCache.get(ckey);
if (!carestriction.isExpired()) {
Util.log(null, Log.WARN, "Already asked once category " + restriction);
result.restricted = carestriction.restricted;
result.asked = true;
return oResult;
}
}
}
// Check if method not asked before once
synchronized (mAskedOnceCache) {
if (mAskedOnceCache.containsKey(mkey)) {
CRestriction marestriction = mAskedOnceCache.get(mkey);
if (!marestriction.isExpired()) {
Util.log(null, Log.WARN, "Already asked once method " + restriction);
result.restricted = marestriction.restricted;
result.asked = true;
return oResult;
}
}
}
// Check if whitelist not asked before
if (restriction.extra != null && hook != null && hook.whitelist() != null) {
CSetting skey = new CSetting(restriction.uid, hook.whitelist(), restriction.extra);
synchronized (mSettingCache) {
if (mSettingCache.containsKey(skey)) {
String value = mSettingCache.get(skey).getValue();
if (value != null) {
Util.log(null, Log.WARN, "Already asked whitelist " + skey);
result.restricted = Boolean.parseBoolean(value);
result.asked = true;
return oResult;
}
}
for (String xextra : getXExtra(restriction, hook)) {
CSetting xkey = new CSetting(restriction.uid, hook.whitelist(), xextra);
if (mSettingCache.containsKey(xkey)) {
String value = mSettingCache.get(xkey).getValue();
if (value != null) {
Util.log(null, Log.WARN, "Already asked whitelist " + xkey);
result.restricted = Boolean.parseBoolean(value);
result.asked = true;
return oResult;
}
}
}
}
}
final OnDemandDialogHolder holder = new OnDemandDialogHolder();
// Build dialog parameters
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.type = WindowManager.LayoutParams.TYPE_PHONE;
params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE;
params.dimAmount = 0.85f;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.format = PixelFormat.TRANSLUCENT;
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
params.gravity = Gravity.CENTER;
// Get window manager
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
// Show dialog
mHandler.post(new Runnable() {
@Override
public void run() {
try {
// Build dialog
holder.dialog = getOnDemandView(restriction, hook, appInfo, result, context, holder, oResult);
// Handle reset button
((Button) holder.dialog.findViewById(R.id.btnReset)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((ProgressBar) holder.dialog.findViewById(R.id.pbProgress)).setProgress(cMaxOnDemandDialog * 20);
holder.reset = true;
holder.latch.countDown();
}
});
// Make dialog visible
wm.addView(holder.dialog, params);
// Update progress bar
Runnable runProgress = new Runnable() {
@Override
public void run() {
if (holder.dialog != null && holder.dialog.isShown()) {
// Update progress bar
ProgressBar progressBar = (ProgressBar) holder.dialog.findViewById(R.id.pbProgress);
if (progressBar.getProgress() > 0) {
progressBar.incrementProgressBy(-1);
mHandler.postDelayed(this, 50);
}
// Check if activity manager locked
if (isAMLocked(restriction.uid)) {
Util.log(null, Log.WARN, "On demand dialog locked " + restriction);
((Button) holder.dialog.findViewById(R.id.btnDontKnow)).callOnClick();
}
}
}
};
mHandler.postDelayed(runProgress, 50);
// Enabled buttons after one second
boolean repeat = (SystemClock.elapsedRealtime() - mOnDemandLastAnswer < 1000);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (holder.dialog != null && holder.dialog.isShown()) {
holder.dialog.findViewById(R.id.btnAllow).setEnabled(true);
holder.dialog.findViewById(R.id.btnDontKnow).setEnabled(true);
holder.dialog.findViewById(R.id.btnDeny).setEnabled(true);
}
}
}, repeat ? 0 : 1000);
} catch (NameNotFoundException ex) {
Util.log(null, Log.WARN, ex.toString());
} catch (Throwable ex) {
Util.bug(null, ex);
}
}
});
// Wait for choice, reset or timeout
do {
holder.reset = false;
boolean choice = holder.latch.await(cMaxOnDemandDialog, TimeUnit.SECONDS);
if (holder.reset) {
holder.latch = new CountDownLatch(1);
Util.log(null, Log.WARN, "On demand reset " + restriction);
} else if (choice)
oResult.ondemand = true;
else
Util.log(null, Log.WARN, "On demand timeout " + restriction);
} while (holder.reset);
mOnDemandLastAnswer = SystemClock.elapsedRealtime();
// Dismiss dialog
mHandler.post(new Runnable() {
@Override
public void run() {
View dialog = holder.dialog;
if (dialog != null)
wm.removeView(dialog);
}
});
} finally {
mOndemandSemaphore.release();
}
} finally {
Binder.restoreCallingIdentity(token);
}
} catch (Throwable ex) {
Util.bug(null, ex);
}
return oResult;
}
use of android.widget.ProgressBar in project LuaViewSDK by alibaba.
the class CustomLoading method initPanel.
@Override
public void initPanel() {
final View lvLoadingView = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleSmallInverse);
LayoutParams relativeLayout = LuaViewUtil.createRelativeLayoutParamsWW();
relativeLayout.addRule(RelativeLayout.CENTER_IN_PARENT);
lvLoadingView.setVisibility(View.VISIBLE);
addView(lvLoadingView, relativeLayout);
}
Aggregations