2013年2月11日月曜日

rel="nofollow"って何?


HTMLでのリンクタグの<a>の属性で、
GoogleやYahooなどの検索エンジンでリンクタグの属性に「rel=nofollow」がついているものは、SEOてきなものには関係ない、追跡しない、そうです。
<a href="http://google.com/" rel="nofollow">

ソースコードを華麗に載せましょうか。(Syntax Highlighter)

さて、無事Syntax Highlighterを使ってソースコードを綺麗に載せられました!

ということで、そのSyntax Highlighterの導入方法をご紹介。

How to Add Syntax Highlighter(v3) to Blogger Blogs

こちらのSyntax Highlighterの導入タグを生成してくれる
Syntax Highlighter Scripts Generator
を使います!



  1. Syntax Highlighter Scripts Generatorにアクセス。
  2. Select a Themeでテーマを選択(ご自由に)
  3. Select Brushesで使用するプログラミング言語もしくはスクリプト言語を選択
  4. Generateボタンを押す
  5. 生成されたソースをコピー
  6. BloggerのHTML編集に行って、headタグ内の最後辺りにでも貼り付け

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeEclipse.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJavaFX.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'></script>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'></script>
<script language="javascript" type="text/javascript">
 SyntaxHighlighter.config.bloggerMode = true;
 SyntaxHighlighter.all();
</script>


ここまでで準備OK!

そしたら、あとは

<pre class='brush:[brushname];'>

  <!--ここに載せたいソースコード-->

</pre>


具体的には

<pre class='brush: java;'>

public class HelloWorld {
  public static void main (String[] args) {
    System.out.println("Hello World !!");
  }
}   

</pre>


結果、こうなる!

public class HelloWorld {
  public static void main (String[] args) {
    System.out.println("Hello World !!");
  }
}   

JavaScriptのファイルの参照先が外部リンクだから、
 もしかしたら勝手にサイトが変えられてしまう!?
...なんてことも可能性があるが、そんなこといったてしょうがないですねw
使わせてもらってるので感謝です。


Syntax Highlighterが使用可能かテストです!

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class STActivity extends FragmentActivity {

 /**
  * The {@link android.support.v4.view.PagerAdapter} that will provide
  * fragments for each of the sections. We use a
  * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
  * will keep every loaded fragment in memory. If this becomes too memory
  * intensive, it may be best to switch to a
  * {@link android.support.v4.app.FragmentStatePagerAdapter}.
  */
 SectionsPagerAdapter mSectionsPagerAdapter;

 /**
  * The {@link ViewPager} that will host the section contents.
  */
 ViewPager mViewPager;

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

  // Create the adapter that will return a fragment for each of the three
  // primary sections of the app.
  mSectionsPagerAdapter = new SectionsPagerAdapter(
    getSupportFragmentManager());

  // Set up the ViewPager with the sections adapter.
  mViewPager = (ViewPager) findViewById(R.id.pager);
  mViewPager.setAdapter(mSectionsPagerAdapter);

 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_st, menu);
  return true;
 }

 /**
  * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
  * one of the sections/tabs/pages.
  */
 public class SectionsPagerAdapter extends FragmentPagerAdapter {

  public SectionsPagerAdapter(FragmentManager fm) {
   super(fm);
  }

  @Override
  public Fragment getItem(int position) {
   // getItem is called to instantiate the fragment for the given page.
   // Return a DummySectionFragment (defined as a static inner class
   // below) with the page number as its lone argument.
   Fragment fragment = new DummySectionFragment();
   Bundle args = new Bundle();
   args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
   fragment.setArguments(args);
   return fragment;
  }

  @Override
  public int getCount() {
   // Show 3 total pages.
   return 3;
  }

  @Override
  public CharSequence getPageTitle(int position) {
   switch (position) {
   case 0:
    return getString(R.string.title_section1).toUpperCase();
   case 1:
    return getString(R.string.title_section2).toUpperCase();
   case 2:
    return getString(R.string.title_section3).toUpperCase();
   }
   return null;
  }
 }

 /**
  * A dummy fragment representing a section of the app, but that simply
  * displays dummy text.
  */
 public static class DummySectionFragment extends Fragment {
  /**
   * The fragment argument representing the section number for this
   * fragment.
   */
  public static final String ARG_SECTION_NUMBER = "section_number";

  public DummySectionFragment() {
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
   // Create a new TextView and set its text to the fragment's section
   // number argument value.
   TextView textView = new TextView(getActivity());
   textView.setGravity(Gravity.CENTER);
   textView.setText(Integer.toString(getArguments().getInt(
     ARG_SECTION_NUMBER)));
   return textView;
  }
 }

}

良いですね!
無事表示されました!

2013年2月4日月曜日

AudioTrackメモメモ2

AudioTrackの使い方備忘録その2


サンプリング周波数決めるときに適当に決めるのもなんなので、

AudioTrack.getNativeOutputSampleRate(streamType);
を使ったらよさげな値を得られる!

Galaxy Nexusでやったら、44100が返ってきた!

AudioTrackメモメモ1

AudioTrackの使い方備忘録その1

まずAudioTrackっていうのは、AndroidでPCMのように音を発生させたいときに使うクラス。


自分のソースそのままコピペしただけだから、分かりにくいと思うが下記のように作成。

        //AudioTrackオブジェクトの作成
        mAudioTrack = new AudioTrack(
                streamType,                   //streamType
                mSampleRate,              //サンプリング周波数
                channel,         //モノラルとか
                encoding,            //audioFormat
                mSampleRate*2,     //バッファサイズ(バイト単位)
                AudioTrack.MODE_STREAM);          //static or stream


streamTypeは、AudioManager.STREAM_MUSICとか。
この場合、音楽用。

encodingは、AudioFormat.ENCODING_PCM_16BITとか。
この場合、shortを使うということ。

channelは、 AudioFormat.CHANNEL_OUT_MONOとか。
これはモノラル。

バッファサイズはwriteした時の貯めておけるメモリサイズ。
ちなみに、バイト数で指定。
私は1秒分を指定したのでサンプル数を×2した。