500GB 外付けHD

Buffalo ポータプルHDD
HD-PEU2

ハードディスク関連の仕事をしていた人から貰った。

クラウドあるから別にHDDいらないな。しかも、今1TBあるし。。

storage service

cloud storage serviceを比較してみる

まずboxから。

box
https://www.box.com/ja-jp/cloud-storage

5GBまで無料とある。¥1200/月で、100GBまで無料。
S3にしろ、サーバーコストがかかるはずなのに、どうやって無料にしているんだろうか?
hirokuか?

UIは普通。割とユーザー数が多そうな印象ではある。Sign inすると英語になる。

uploadすると、、、

無料のストレージサービス、いっぱいあるから、何が嬉しいのかよくわからんね。

activity_main xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ffaa88"
    tools:context=".MainActivity">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/word"/>
        <EditText
            android:id="@+id/uriname"
            android:inputType="text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >
        <Button
            adnroid:id="@+id/post"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="@string/post" />
        <Button
            android:id="@+id/browser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="@string/browser" />
    </LinearLayout>

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

mainActivity

package com.capital.connectmysql;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private UploadTask task;
    private TextView textView;
    private EditText editText;

    String url = "http://hpscript/android/pass_check.html";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.uriname);

        Button post = findViewById(R.id.post);

        post.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                String param0 = editText.getText().toString();

                if(param0.length() != 0){
                    task = new UploadTask();
                    task.setListener(createListener());
                    task.execute(param0);
                }
            }
        });

        Button browser = findViewById(R.id.browser);
        browser.setOnClickListener(new View.OnClickListenr(){
            @Override
            public void onClick(View v){
                Uri uri = Uri.parse(url);
                Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);

                textView.setText("");
            }
        });
        textView = findViewById(R.id.text_view);
    }

    @Override
    protected void onDestroy(){
        task.setListener(null);
        super.onDestory();
    }

    private UploadTask.Listener createListener(){
        return new UploadTask.Listener(){
            @Override
            public void onSuccess(String result){
                textView.setText(result);
            }
        };
    }
}
package com.capital.connectmysql;

import android.net.sip.SipAudioCall;
import android.os.AsyncTask;
import android.util.Log;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class UploadTask extends AsyncTask<String, Void, String> {

    private SipAudioCall.Listener listener;

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

        String urlSt = "http://hpscript.com/";

        HttpURLConnection con = null;
        String result = null;
        String word = "word="+params[0];

        try {
            URL url = new URL(urlSt);

            con = (HttpURLConnection) url.openConnection();

            con.setRequestMethod("POST");
            con.setInstanceFollowRedirects(false);
            con.setDoOutput(true);

            con.setReadTimeout(10000);
            con.setConnectTimeout(20000);

            con.connect();

            OutputStream out = null;
            try {
                out = con.getOutputStream();
                out.write( word.getBytes("UTF-8"));
                out.flush();
                Log.d("dubug", "flush");
            } catch (IOException e){
                e.printStackTrack();
                result = "POST送信エラー";
            } finally {
                if (out != null){
                    out.close();
                }
            }
            final int status = con.getResponseCode();
            if (status == HttpURLConnection.HTTP_OK){
                result = "HTTP_OK";
            } else {
                result = "status="+String.valueOf(status);
            }
        } catch(IOException e){
            e.printStackTrace();
        } finally {
            if (con != null){
                con.disconnect();
            }
        }
        return result;
    }

    @Override
    protected void onPostExecute(String result){
        super.onPostExecute(result);

        if(listener != null){
            listener.onSuccess(result);
        }
    }

    void setListener(SipAudioCall.Listener listener){
        this.listener = listener;
    }

    interface Listener {
        void onSuccess(String result);
    }
}

Android Studioでdependencyを追加する。

file -> project structure を押す

dependency -> libraries dependency を選択する

dependenciesが追加される。

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'org.jdom:jdom2:2.0.6'
}

list view

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/textView" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:id="@+id/textView2"
        android:layout_weight="0.08" />
</LinearLayout>

rss parse

package com.capital.anew;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Handler handler;
    private final String RSS_URL = "http://m-shige1979.hatenablog.com/rss";
    private TextView text1;
    private String RssText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handler = new Handler();
        setContentView(R.layout.activity_main);
        text1 = (TextView)findViewById(R.id.textview1);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){

        MenuItem item1 = menu.add("UPDATE");
        item1.setIcon(android.R.drawable.ic_menu_upload);

        item1.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
            @Override
            public boolean onMenuItemClick(MenuItem item){

                Thread thread1 = new Thread(){
                    @Override
                    public void run(){
                        try {
                            RssText = RssParse.getRss(MainActivity.this, RSS_URL);

                            handler.post(new Runnable(){
                                @Override
                                public void run(){
                                    text1.setText(RssText);
                                    Toast.makeText(MainActivity.this, "読み込み終了", Toast.LENGTH_SHORT).show();

                                }
                            });
                        } catch (Exception e){
                            Log.d("sample", e.getMessage());
                        }
                    }
                };
                thread1.start();
                return false;
            }
        });

        item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        getMenuInflater().inflate(R.menu.menu_main, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        int id = item.getItemId();

        if(id == R.id.action_settings){
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}

package com.capital.anew;

import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class parse {
public static String getRss(Context context, String url)
throws IOException {

StringBuilder sb = new StringBuilder();

AndroidHttpClient client = AndroidHttpClient.newInstance(“TEST”);
HttpGet get = new HttpGet(url);

try {
HttpResponse response = client.execute(get);

BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = null;
while((line = br.readLine()) != null){
sb.append(line);
}
} finally {
client.close();
}
return sb.toString();
}
}
[/code]