Архив

Архив Март 2023
14 марта 2023 Нет комментариев
show variables like '%pack%';
set global max_allowed_packet=1073741824;
Categories: MySQL Tags:
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        webView = findViewById(R.id.webView);
        if(isNetworkConnected(this)){
            webView.loadUrl("https://site.ru/");
        }
        else{
            webView.loadUrl("file:///android_asset/lost.html");
        }
    }
    private boolean isNetworkConnected(Context context) {
        ConnectivityManager cm =
                (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    }
}
Categories: Android Tags:
public class MainActivity extends AppCompatActivity {
    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        webView = findViewById(R.id.webView);
        webView.setWebViewClient(new CustomWebViewClient());
    }
    private class CustomWebViewClient extends WebViewClient{
        @Override
        public void onPageFinished(WebView view, String url) {
            String username = "";
            String cookies_all = CookieManager.getInstance().getCookie(url);
            if (cookies_all != null) {
                String[] cookies_array = cookies_all.split(";");
                for (String cookie : cookies_array) {
                    String[] cookie_array = cookie.split("=");
                    if (cookie_array[0].contains("users")){
                        String[] user_data = cookie_array[1].split("%");
                        username=user_data[0];
                        if (!Objects.equals(username, "")) {
                            Toast.makeText(view.getContext(), username, Toast.LENGTH_LONG).show();
                        }
                    }
                }
            }
            super.onPageFinished(view, url);
        }
    }
}
Categories: Android Tags:

AndroidManifest.xml

<application
	android:theme="@style/Theme.Test.Launcher"
</application>

themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="Theme.Test.Launcher">
        <item name="android:windowBackground">@drawable/launch_screen</item>
    </style>
</resources>

launch_screen.xml для векторного изображения

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
    <item android:drawable="@color/orange"/>
    <item android:drawable="@drawable/logo_splash" android:gravity="center"/>
</layer-list>

launch_screen.xml для png

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
    <item android:drawable="@color/red"/>
    <item>
        <bitmap
            android:src="@drawable/logo_splash"
            android:gravity="center"/>
    </item>
</layer-list>

MainActivity.java

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.Theme_Test);
        super.onCreate(savedInstanceState);
    }
}
Categories: Android Tags:

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"/>
    <ProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:indeterminateTint="@color/orange"/>
</RelativeLayout>

Для своей картинки вместо стандартного ProgressBar:

    <ProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:indeterminateDrawable="@drawable/progress"/>

progress.xml

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/progress_icon"
    android:pivotX="50%"
    android:pivotY="50%"/>

MainActivity.java

public class MainActivity extends AppCompatActivity {
    private WebView webView;
    private ProgressBar spinner;
    String ShowOrHideWebViewInitialUse = "show";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        webView = findViewById(R.id.webView);
        spinner = findViewById(R.id.progress);
        webView.setWebViewClient(new CustomWebViewClient());
    }
    private class CustomWebViewClient extends WebViewClient{
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon){
            spinner.setVisibility(View.VISIBLE);
            if(ShowOrHideWebViewInitialUse.equals("show")){
                view.setVisibility(View.INVISIBLE);
            }
        }
        @Override
        public void onPageFinished(WebView view, String url){
            ShowOrHideWebViewInitialUse = "hide";
            spinner.setVisibility(View.GONE);
            view.setVisibility(View.VISIBLE);
            super.onPageFinished(view, url);
        }
     }
}
Categories: Android Tags:

build.gradle

dependencies {
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"/>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {
    private WebView webView;
    private SwipeRefreshLayout swipeRefreshLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        webView = findViewById(R.id.webView);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeRefreshLayout.setRefreshing(true);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeRefreshLayout.setRefreshing(false);
                        webView.reload();
                    }
                },3000);
            }
        });
        swipeRefreshLayout.setColorSchemeColors(
                getResources().getColor(R.color.orange)
        );
    }
}
Categories: Android Tags:
public class MainActivity extends AppCompatActivity {
    private WebView webView;
    @Override
    public void onBackPressed(){
        if(webView.canGoBack()){
            webView.goBack();
        }
        else{
            super.onBackPressed();
        }
    }
}
Categories: Android Tags: