Android Set Пользовательский шрифт из веб-страницы

Если вы добавите оператор указателя * к указателю, вы перенаправляете его с указателя на объект, на который указывает.

Примеры:

int i = 0;
int *p = &i; // <-- N.B. the pointer declaration also uses the `*`
             //     it's not the dereference operator in this context
*p;          // <-- this expression uses the pointed-to object, that is `i`
p;           // <-- this expression uses the pointer object itself, that is `p`

Поэтому:

*ipp = ip2; // <-- you change the pointer `ipp` points to, not `ipp` itself
            //     therefore, `ipp` still points to `ip1` afterwards.
0
задан Khun Htet Naing 13 July 2018 в 12:07
поделиться

1 ответ

Я написал пример проекта:

Код JAVA:

import android.app.*;
import android.os.*;
import android.widget.*;
import android.graphics.*;
import java.io.*;
import android.view.*;
import java.net.*;
import android.util.*;

/*************
CODED BY : SIROS BAGHBAN 
DATE : 13/7/2018
*/

public class MainActivity extends Activity 
{
    private TextView MyText;
    private Button MyButt;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        MyText =(TextView)findViewById(R.id.fonta);
        MyButt =(Button)findViewById(R.id.butt);

        loadfont();

        MyButt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {           
                    loadfont();
                }
            });
    }


    // Load font if available on SD
    private void loadfont () {
        File file = new File("/mnt/sdcard/myfont.ttf");
        if(file.exists()){

            // Display font from SD
            Typeface typeFace = Typeface.createFromFile(
            new File(Environment.getExternalStorageDirectory(), "/myfont.ttf"));
            MyText.setTypeface(typeFace);

        }
        else {       

            download();
        }
    }

    // Download the custom font from the URL
    private void download () {

        new DownloadFileFromURL().execute("http://webpagepublicity.com/free-fonts/x/Xtrusion%20(BRK).ttf"); // Downlod LINK !

    }


// File download process from URL
private class DownloadFileFromURL extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
    @Override
    protected String doInBackground(String... f_url) {
        int count;
        try {
            URL url = new URL(f_url[0]);
            URLConnection conection = url.openConnection();
            conection.connect();
            int lenghtOfFile = conection.getContentLength();
            InputStream input = new BufferedInputStream(url.openStream(), 8192);
            OutputStream output = new FileOutputStream("/sdcard/myfont.ttf");
            byte data[] = new byte[1024];
            long total = 0;
            while ((count = input.read(data)) != -1) {
                total += count;
                publishProgress(""+(int)((total*100)/lenghtOfFile));
                output.write(data, 0, count);
            }
            output.flush();
            output.close();
            input.close();

        } catch (Exception e) {
            Log.e("Error: ", e.getMessage());
        }
        return null;
    }
    @Override
    protected void onPostExecute(String file_url) {
        // Display the custom font after the File was downloaded !
        loadfont();
    }
}
 }

Код XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Show me the custom font !"
        android:id="@+id/butt"
        android:layout_centerInParent="true"/>

    <TextView
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="wrap_content"
        android:text="Custom FONT !"
        android:layout_above="@id/butt"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="30dp"
        android:id="@+id/fonta"/>

</RelativeLayout>

Добавьте эти разрешения в файл манифеста:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

Примечание. Включите Интернет для проверки проекта:)

удачи.

0
ответ дан Siros Baghban 17 August 2018 в 12:59
поделиться
Другие вопросы по тегам:

Похожие вопросы: