Servis ve Bildirim


<service android:name=".Service.ServiceNoti" />


public class ServiceNoti extends Service {
    public static List burclar = new ArrayList();
    Timer timing;
    Handler helper;
    int bildakika=-1;
    final static long scheduleTime = 1000*5;
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public void onCreate() {
        super.onCreate();

        if(burclar.isEmpty()){
            ekleBurc();
        }else{
            burcOku();
        }
        super.onCreate();

        timing = new Timer();
        helper= new Handler(Looper.getMainLooper());
        timing.scheduleAtFixedRate(new TimerTask() {


            @Override
            public void run() {
                callMethod();
            }

            private void callMethod() {
                final int[] time = {0,0};
                helper.post(new Runnable() {
                    public void run() {

                        java.util.Calendar c = java.util.Calendar.getInstance();
                        time[0] =c.get(java.util.Calendar.HOUR_OF_DAY );
                        time[1] =c.get(Calendar.MINUTE );
                        System.out.println("Ay . Timer check...");


                        System.out.println("Ay . Timer check :"+ time[0]+" : "+time[1]);

                        if(bildakika!=time[1]){
                            if (time[0]== 15 &&  time[1]==0) {
                                System.out.println("Ay . check");
                                Notification();
                                bildakika=time[1];
                            }

                        }else {
                            if (time[1]!=0){
                                bildakika=-1;
                            }
                        }

                        //Notification(words.get(0).getWord().toString(),0,3);
                        System.out.println("Girdi??"+c.get(java.util.Calendar.HOUR_OF_DAY));
                        //checkOdev();
                        //checkSinav();


                    }
                });
            }

        }, 5, scheduleTime);
    }
    public void Notification() {
        Intent in = new Intent(getApplicationContext(),Splash.class);

        // Open NotificationView.java Activity
        PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, in,
                PendingIntent.FLAG_UPDATE_CURRENT);
        //Create Notification using NotificationCompat.Builder
        NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
                // Set Icon
                .setSmallIcon(R.drawable.ic_logos)
                // Set Ticker Message
                .setTicker("Burç Yorumunu Okudun mu?")
                // Set Title
                .setContentTitle("Burç Yorumunu Okudun mu?")
                // Set Text
                .setContentText("Günlük burç yorumunu okumak için dokun.")
                .setStyle(new NotificationCompat.BigTextStyle().bigText("Günlük burç yorumunu okumak için dokun."))
                // Add an Action Button below Notification
                // Set PendingIntent into Notification
                .setContentIntent(pIntent)
                // Dismiss Notification
                .setAutoCancel(true);

        builder.setVibrate(new long[] { 1000, 1000 });

        //LED
        builder.setLights(Color.YELLOW, 3000, 3000);

        //Ton
        builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);



        NotificationManager notificationmanager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        // Build Notification with Notification Manager

        notificationmanager.notify(10057, builder.build());

    }
}


Shared Preference


public void burcOku(){
        SharedPreferences sharedPrefs = getApplicationContext().getSharedPreferences("burclar", Context.MODE_PRIVATE);
        Gson gson = new Gson();
        String json = sharedPrefs.getString("burcx"null);
        Type type = new TypeToken>() {}.getType();
        try {
            if(gson.fromJson(json, type)!=null) {
                ServiceNoti.burclar = gson.fromJson(json, type);
            }
        } catch (NumberFormatException e) {
            System.out.println("Herşey Düzelir...");
        }
    }
    public static void burcYaz(Context context){
        SharedPreferences sharedPrefs = context.getSharedPreferences("burclar", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPrefs.edit();
        Gson gson = new Gson();

        String json = gson.toJson(ServiceNoti.burclar);

        editor.putString("burcx", json);
        editor.commit();
    }


Splash Screen


Styles :


<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">    <item name="android:windowBackground">@drawable/splashx</item></style>

Drawable :


<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item        android:drawable="@drawable/backxx"/>
    <item>        <bitmap            android:gravity="center"            android:src="@drawable/splashburc"/>    </item>


</layer-list>


Splash Class :

public class Splash extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_splash); 

        if(isMyServiceRunning(ServiceNoti.class)==false) { 
            startService(new Intent(this, ServiceNoti.class)); 
        } 


        Thread timerThread = new Thread() { 
            public void run() { 
                try { 
                    sleep(500); 
                } catch (InterruptedException e) { 
                    e.printStackTrace(); 
                } finally { 

                        Intent intent = new Intent(Splash.this, Mainx.class); 
                        startActivity(intent); 


                } 
            } 
        }; 
        timerThread.start(); 
    } 
    @Override 
    protected void onPause() { 
        // TODO Auto-generated method stub 
        super.onPause(); 
        finish(); 
    } 
    private boolean isMyServiceRunning(Class<?> serviceClass) { 
        ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(service.service.getClassName())) { 
                return true
            } 
        } 
        return false
    } 
}

Back Button 

ActionBar bar = getSupportActionBar(); 
        bar.setDisplayHomeAsUpEnabled(true);

public boolean onOptionsItemSelected(MenuItem item) { 
        switch (item.getItemId()) { 
            case android.R.id.home: 
                finish(); 
                return true
            default
                return super.onOptionsItemSelected(item); 
        } 
    }


HttpHandler

public class HttpHandler { 

    private static final String TAG = HttpHandler.class.getSimpleName(); 

    public HttpHandler() { 
    } 

    public String makeServiceCall(String reqUrl) { 
        String response = null
        try { 
            URL url = new URL(reqUrl); 
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET"); 
            // read the response 
            InputStream in = new BufferedInputStream(conn.getInputStream()); 
            response = convertStreamToString(in); 
        } catch (MalformedURLException e) { 
            Log.e(TAG, "MalformedURLException: " + e.getMessage()); 
        } catch (ProtocolException e) { 
            Log.e(TAG, "ProtocolException: " + e.getMessage()); 
        } catch (IOException e) { 
            Log.e(TAG, "IOException: " + e.getMessage()); 
        } catch (Exception e) { 
            Log.e(TAG, "Exception: " + e.getMessage()); 
        } 
        return response; 
    } 

    private String convertStreamToString(InputStream is) { 
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder(); 

        String line; 
        try { 
            while ((line = reader.readLine()) != null) { 
                sb.append(line).append('\n'); 
            } 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } finally { 
            try { 
                is.close(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
        } 

        return sb.toString(); 
    } 
}



GetData

public class getData extends AsyncTask<Void, Void, Void> { 
    Context context; 
    ProgressDialog progressDialog; 
    private static String URLay="http://bilgimahseniastroloji.pe.hu/aylik.json"; 
    /*private static String[] URLgun = {"http://www.falbaktir.net/gunluk-burc-koc", 
     "http://www.falbaktir.net/gunluk-burc-boga", 
    "http://www.falbaktir.net/gunluk-burc-ikizler", 
    "http://www.falbaktir.net/gunluk-burc-yengec", 
    "http://www.falbaktir.net/gunluk-burc-aslan", 
    "http://www.falbaktir.net/gunluk-burc-basak", 
    "http://www.falbaktir.net/gunluk-burc-terazi", 
    "http://www.falbaktir.net/gunluk-burc-akrep", 
    "http://www.falbaktir.net/gunluk-burc-yay", 
    "http://www.falbaktir.net/gunluk-burc-oglak", 
    "http://www.falbaktir.net/gunluk-burc-kova", 
    "http://www.falbaktir.net/gunluk-burc-balik"};*/ 

    private static String URLyeniGun="http://bilgimahseniastroloji.pe.hu/denemex.json"; 
    public getData(Context context){
        this.context=context;
    }
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        progressDialog = new ProgressDialog(context);
        progressDialog.setTitle("Lütfen Bekleyiniz");
        progressDialog.setMessage("Veriler Alnıyor...");
        progressDialog.setIndeterminate(false);
        progressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {

        /*try{
            for (int i = 0; i< ServiceNoti.burclar.size(); i++){

                Document doc  = Jsoup.connect(URLgun[i]).get();
                ServiceNoti.burclar.get(i).setGunlukTarih(doc.select("h4").text());
                ServiceNoti.burclar.get(i).setAsk(doc.select("p").get(1).getAllElements().text());
                ServiceNoti.burclar.get(i).setIs(doc.select("p").get(2).getAllElements().text());
                ServiceNoti.burclar.get(i).setPara(doc.select("p").get(3).getAllElements().text());
                ServiceNoti.burclar.get(i).setDikkat(doc.select("p").get(4).getAllElements().text());
            }

        }catch (Exception e){
            Toast.makeText(context, "Hata!... 'Güncelle' butonuna basınız.",
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }*/

        try{

            HttpHandler sh = new HttpHandler();
            String jsonStr = sh.makeServiceCall(URLyeniGun);
            JSONObject jsonObj = new JSONObject(jsonStr);
            String tarih = jsonObj.getString("tarih");
            JSONArray aylar = jsonObj.getJSONArray("gunlukyorumlar");



            for(int i=0;i<aylar.length();i++){
                JSONObject a = aylar.getJSONObject(i);
                String ask = a.getString("ask");
                String is = a.getString("is");
                String para = a.getString("para");
                String dikkat = a.getString("dikkat");
                ServiceNoti.burclar.get(i).setGunlukTarih(tarih);
                ServiceNoti.burclar.get(i).setAsk(ask);
                ServiceNoti.burclar.get(i).setIs(is);
                ServiceNoti.burclar.get(i).setPara(para);
                ServiceNoti.burclar.get(i).setDikkat(dikkat);
                System.out.println("Ay . ask :"+(i+1)+" "+ask);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        try{

            HttpHandler sh = new HttpHandler();
            String jsonStr = sh.makeServiceCall(URLay);
            JSONObject  jsonObj = new JSONObject(jsonStr);
            JSONArray aylar = jsonObj.getJSONArray("aylikyorumlar");



            for(int i=0;i<aylar.length()-1;i++){
                JSONObject a = aylar.getJSONObject(i);
                String ad = a.getString("ad");
                String yorum = a.getString("yorum");
                ServiceNoti.burclar.get(i).setAylikYorum(yorum);
            }
        }catch (Exception e){
            e.printStackTrace();
        }


        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {

        progressDialog.dismiss();
    }
}


PHP jeton Getir

<?php 
    $con=mysqli_connect("localhost","dnzcskn","Deneme57","StudentsCoin"); 
    mysqli_set_charset($con,"utf8"); 
     
     
    $statement =mysqli_prepare($con,"select * from coins order by coin_number desc limit 100");
    mysqli_stmt_execute($statement); 
     
    mysqli_stmt_store_result($statement); 
     
    mysqli_stmt_bind_result($statement,$coin_id,$coin_mail,$coin_nick,$coin_number); 
     
     
    $JSON["dizi"]=array(); 
    $user=array(); 

         
    while(mysqli_stmt_fetch($statement)){ 
        $user["coin_id"]=$coin_id; 
        $user["coin_mail"]=$coin_mail; 
        $user["coin_nick"]=$coin_nick; 
        $user["coin_number"]=$coin_number; 
        array_push($JSON['dizi'],$user); 
         
    } 
     
    echo json_encode($JSON); 
    mysqli_stmt_close($statement); 
     
    mysqli_close($con); 

?>

PHP Kayıt

<?php 
    $conn=mysqli_connect("localhost","dnzcskn","Deneme57","StudentsCoin"); 
    mysqli_set_charset($conn,"utf8"); 

    $durum="true"

     
    $coin_mail=$_POST["coin_mail"]; 
    $coin_nick=$_POST["coin_nick"]; 
    $coin_number=$_POST["coin_number"]; 
     
    $statement =mysqli_prepare($conn,"INSERT INTO coins(coin_mail,coin_nick,coin_number) VALUES (?,?,?)");
     
    mysqli_stmt_bind_param($statement,"ssi",$coin_mail,$coin_nick,$coin_number); 
     
    mysqli_stmt_execute($statement); 
    if (mysqli_stmt_errno($statement)===1062) { 
               $durum="false"
         
    } 
    echo $durum; 
    mysqli_stmt_close($statement); 
     
    mysqli_close($conn); 

     

?>

PHP jeton güncelle

<?php 
    $conn=mysqli_connect("localhost","dnzcskn","Deneme57","StudentsCoin"); 
    mysqli_set_charset($conn,"utf8"); 
    $coin_mail=$_POST["coin_mail"]; 
    $coin_number=$_POST["coin_number"]; 
     
    $statement =mysqli_prepare($conn,"update coins set coin_number= ? where coin_mail = ?");
     
    mysqli_stmt_bind_param($statement,"i",$coin_number); 
         
    mysqli_stmt_execute($statement); 
     
    mysqli_stmt_close($statement); 
     
    mysqli_close($conn); 
?>

PHP mail Getir

<?php 
    $conn=mysqli_connect("localhost","dnzcskn","Deneme57","StudentsCoin"); 
     
    $coin_mail=$_POST["coin_mail"]; 
     
     
    $statement =mysqli_prepare($con,"select * from coins where coin_mail = ?"); 
    mysqli_stmt_bind_param($statement,"s",$coin_mail);  
    mysqli_stmt_execute($statement); 
     
    mysqli_stmt_store_result($statement); 
     
    mysqli_stmt_bind_result($statement,$coin_id,$coin_mail,$coin_nick,$coin_number);
     
    $user=array(); 
     
    while(mysqli_stmt_fetch($statement)){ 
        $user[coin_id]=$coin_id; 
        $user[coin_mail]=$coin_mail; 
        $user[coin_nick]=$coin_nick; 
        $user[coin_number]=$coin_number; 
         
    } 
    echo json_encode($user); 
     
    mysqli_stmt_close($statement); 
     
    mysqli_close($con); 

?>

Mulakat

public class mulakat { 
    static ArrayList<Integer> sayilar = new ArrayList<Integer>(); 
    static ArrayList<Integer> asalSayilar = new ArrayList<Integer>(); 
    public static void main(String[] args) { 
        Scanner in = new Scanner(System.in); 
        int n = in.nextInt(); 
        //int sonuc=fibonacci(n); 
        //int sonuc=enBuyukAsal(n); 
        //int sonuc=asallariBul(n); 
        //System.out.println(sonuc); 
        double var1 = 1 + 5; 
        double var2 = var1 / 4; 
        int var3 = 1 + 5; 
        int var4 = var3 / 4; 
        System.out.print(var2 + " " + var4); 
    } 
    public static  int fibonacci(int n){ 
        int sayac1=1,sayac2=1,toplam=0; 
        sayilar.add(sayac1); 
        sayilar.add(sayac2); 
        System.out.println(sayac1+" "+sayac2); 
        for(int i=2;;i++){ 
            if(sayac2>n){ 
                for(int j=0;j<sayilar.size();j++){ 
                    if(sayilar.get(j)%2==0){ 
                        toplam+=sayilar.get(j); 
                    } 
                } 
                return toplam; 
            }else
                int tmp=sayac2; 
                sayac2+=sayac1; 
                sayac1=tmp; 
                sayilar.add(sayac2); 
            } 
            System.out.println(sayac1+" "+sayac2); 
        } 
    } 
    public static int enBuyukAsal(int n){ 
        int asalcarpan=2,kalan=0; 
             
        while (n>1){ 
        kalan=(n %asalcarpan); 
        if (kalan==0){ 

        n=n/asalcarpan; 
        } 
        else if (n>0) 

        asalcarpan++; 

        } 
        return asalcarpan; 
    } 
    public static int asallariBul(int n){ 
        int sayi,sayac=0;  
        for(int i=2; i<=n; i++){  
            sayi=0;  
            for(int j=2; j<=i/2; j++){  
                if(i%j==0) sayi++;  
            }  
            if(sayi==0){ 
                System.out.println(+i); 
                sayac+=+i; 
            } 
        } 
        return sayac; 
    } 
}

«
İleri
Sonraki Kayıt
»
Previous
Önceki Kayıt

Hiç yorum yok:

Yorum Yapın