Unable to resolve 'AppCompatPreferenceActivity' in SettingsActivity - java

I have an AppCompatPreferenceActivity.java. But it shows an error in this
public class SettingsActivity extends AppCompatPreferenceActivity
It says it couldn't resolve 'AppCompatPreferenceActivity'.
And it seems like I am the only one with this problem. Any idea?
Error:(21, 39) error: cannot find symbol class AppCompatPreferenceActivity

AppCompatPreferenceActivity does not existing in google support libary,
you should create a class with same name and use this source:
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
private AppCompatDelegate mDelegate;
#Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}
public void setSupportActionBar(#Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}
#Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}
#Override
public void setContentView(#LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
#Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}
#Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}
#Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}
#Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}
#Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
#Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}
#Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}
public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
}

Related

How to implement admob rewarded video ads in a list view?

I want to know how to implement AdMob rewarded video ads in a list view?
I'm using the source code from here
and I want to use it in this class StickerPackDetailsActivity.java
and the layout is gonna like this
![layout][1]
I want to lock add to WhatsApp and unlock it by watching video reward.
but this stickerdetails showed from listview from
![here][2]
so, how to implement video reward ads only in 1 specified item of the listview not all of them?
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
private RewardedVideoAd mRewardedVideoAd;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this,"ca-app-pub111111111");
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
listitem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
loadRewardedVideoAd();
}
});
}
private void loadRewardedVideoAd() {
mRewardedVideoAd.loadAd("ca-app-pub-",
new AdRequest.Builder().build());
}
#Override
public void onRewardedVideoAdLoaded() {
}
#Override
public void onRewardedVideoAdOpened() {
}
#Override
public void onRewardedVideoStarted() {
}
#Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}
#Override
public void onRewarded(RewardItem rewardItem) {
}
#Override
public void onRewardedVideoAdLeftApplication() {
}
#Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
#Override
public void onRewardedVideoCompleted() {
}
#Override
protected void onPause() {
mRewardedVideoAd.pause(this);
super.onPause();
}
#Override
protected void onResume() {
mRewardedVideoAd.resume(this);
super.onResume();
}
}

Cannot call method from another activity

I cannot call method from another activity in OnNotificationPosted. I also tried to make instance of activity but failed. I searched alot but no success. please help
NotificationListener
public class NotificationListener extends NotificationListenerService {
#Override
public void onCreate() {
super.onCreate();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn) {
otherActivity oth = new otherActivity();
oth.loc();
}
#Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.i("Msg", "Notification Removed");
}
}
otherActivity
public class OtherActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other);
}
public void loc() {
//code body
}
}
public class OtherActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other);
}
public static void loc(){
//code body
}
}
how to using : otherActivity.loc();
public class NotificationListener extends NotificationListenerService {
#Override
public void onCreate() {
super.onCreate();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn) {
otherActivity.loc();
}
#Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.i("Msg","Notification Removed");
}

AsyncTaskLoader - how to?

I use loader to do task in back ground in method loadInBackground i added for loop to print log in logcat 50 time , so when i click the button start print log in logcat
but when i click the button i don't have any action and i don't have ant error , what is problem ?
mainActicity
public class MainActivity extends AppCompatActivity implements android.app.LoaderManager.LoaderCallbacks<String> {
TextView textView;
android.app.LoaderManager loaderManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loaderManager=getLoaderManager();
textView=findViewById(R.id.tv_result);
if (loaderManager.getLoader(0) ==null){
loaderManager.initLoader(0,null,this);
}
}
public void StartMysynstack (View view){
loaderManager.initLoader(0,null,this);
}
#Override
public android.content.Loader<String> onCreateLoader(int i, Bundle bundle) {
return new Myloader(this);
}
#Override
public void onLoadFinished(android.content.Loader<String> loader, String s) {
textView.setText(s);
}
#Override
public void onLoaderReset(android.content.Loader<String> loader) {
}
}
my loader
public class Myloader extends AsyncTaskLoader<String> {
int i;
public Myloader(Context context) {
super(context);
}
#Override
public String loadInBackground() {
for( i=0;i<=100;i++){
try {
Thread.sleep(50);
Log.d("waad","loadInBackground"+i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return "Task result";
}
}
you can try calling it manually.
getLoaderManager().initLoader(0, null, this).forceLoad();
so according to your code you can make following changes.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loaderManager=getLoaderManager();
textView=findViewById(R.id.tv_result);
if (loaderManager.getLoader(0) ==null){
loaderManager.initLoader(0,null,this).forceLoad();;
}
}

Screen turns white after expanding to fullscreen

While debugging on USB I just wanted to expand WebView to fullscreen. Unfortunately, white screen appeared and nothing after it. I really do not know what to do. I made CustomView and everything seemed fine. Here is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filmkey = "<iframe width=\"96%\" height=\"96%\" src=\"https://www.youtube.com/embed/EtMOgsWEAmQ\" frameborder=\"0\" allowfullscreen></iframe>";
screen=(WebView)findViewById(R.id.webView);
screen.getSettings().setJavaScriptEnabled(true);
String myvideokey = filmkey;
screen.loadData(myvideokey, "text/html", "utf-8");
screen.setWebChromeClient(new WebChromeClient(){
#Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
}
#Override
public void onHideCustomView() {
super.onHideCustomView();
}
});
}
try the following Code. In this on full screen i created a View which will become full Screen.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
screen.restoreState(savedInstanceState);
}
setContentView(R.layout.activity_support);
filmkey = "<iframe width=\"96%\" height=\"96%\" src=\"https://www.youtube.com/embed/EtMOgsWEAmQ\" frameborder=\"0\" allowfullscreen></iframe>";
screen=(WebView)findViewById(R.id.webview);
screen.getSettings().setJavaScriptEnabled(true);
String myvideokey = filmkey;
screen.loadData(myvideokey, "text/html", "utf-8");
CustomWebChromeClient custom = new CustomWebChromeClient();
screen.setWebChromeClient(custom);
}
and the custom WebChromeClient is
class `CustomWebChromeClient` extends WebChromeClient{
#Override
public void onShowCustomView(View view, final CustomViewCallback callback) {
super.onShowCustomView(view, callback);
Dialog dialog = new Dialog(SupportActivity.this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
view.setBackgroundColor(Color.TRANSPARENT);
dialog.setContentView(view);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
callback.onCustomViewHidden();
}
});
dialog.show();
}
#Override
public void onHideCustomView() {
super.onHideCustomView();
}
}
and also make sure you use all these methods in the activity to handle with the data in webView.
#Override
protected void onResume() {
super.onResume();
screen.onResume();
}
#Override
protected void onPause() {
super.onPause();
screen.onPause();
}
#Override
protected void onStop() {
super.onStop();
screen.stopLoading();
}
#Override
protected void onDestroy() {
super.onDestroy();
screen.destroy();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
screen.saveState(outState);
}
I hope it helps.

How do I know the state of the ToggleButton from another activity?

How do I know the state of the ToggleButton from another activity?
i have class
public class MainScreen extends Activity{
protected ToggleButton tgbutton;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainscreen);
tgbutton = (ToggleButton)findViewById(R.id.advice);
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
tgbutton.setChecked(sharedPreferences.getBoolean("toggleButton", false));
}
public void oneClick(View v) {
if(tgbutton.isChecked() == false) { playSound(mSound); }
else { pauseSound(mSound); }
}
}
and
public class SmallprintA extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smallprint_a);
OnClickListener SendOnClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
if(tgbutton.isChecked() == true){ playSound(mEmpty); }
else { playSound(mEmpty); }
}
};
}
I need in the class SmallprintA determine the state of the ToggleButton tgbutton. This is possible without class inheritance?
I did tgbutton is static
public class MainScreen extends Activity{
protected static ToggleButton tgbutton; // STATIC
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainscreen);
tgbutton = (ToggleButton)findViewById(R.id.advice);
}
public void oneClick(View v) {
if(tgbutton.isChecked() == false) { playSound(mSound); }
else { pauseSound(mSound); }
}
}
and
public class SmallprintA extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smallprint_a);
OnClickListener SendOnClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
if(MainScreen.tgbutton.isChecked() == true){ playSound(mEmpty); }
else { playSound(mEmpty); }
}
};
}

Categories

Resources